Changing values for multivariable matrix

1 view (last 30 days)
Mastura
Mastura on 11 May 2015
Commented: John D'Errico on 11 May 2015
Hi. My problem is to find the invertibility of a matrix. Inside this 3x3 matrix, I have about 6 variables and for each variable there is an upper and lower limits. So I need to change this variables value then to find its determinant to see if it is zero. I tried using GA in matlab, but i want to confirm the result using somekind of looping algo. But i am not sure how to do it. example
A=[cos(X)cos(Y) sin(J)cos(K) -sin(X)sin(K);
L+cos(J) L*M*sin(Y) M*sin(K);
M*sin(X)sin(Y) L*cos(X) M*sin(Y)sin(K)];
and the values that i must test are:
X=-10:10;
Y=-35:35;
J=-3:3;
K=0:14;
L=1200:11000;
M=35000:44000;
as you can see these variables may not have the same length. Should I used a nested loop to test the values inside the matrix. I don't know where to start. Any suggestion is appreciated.

Answers (2)

John D'Errico
John D'Errico on 11 May 2015
Edited: John D'Errico on 11 May 2015
There are
21*71*7*15*9800*9000
ans =
1.3808e+13
possible combinations of those parameters. So roughly 14 trillion combinations of those variables. Feel free to loop over all combinations, but do have some coffee while you wait. Many cups of it in fact. 14 trillion such computations will be a moderately time consuming task.
A = rand(3);
timeit(@() det(A))
ans =
4.4979e-06
1.38e13*ans
ans =
6.2071e+07
For example, on my cpu, it took a very small fraction of a second for one 3x3 determinant. But 14 trillion of them?
At 4.4979e-06 seconds per computation of a determinant, and roughly 31.5 million seconds in a year, my CPU would take
1.38e13/(31.5e6/4.4979e-06)
ans =
1.9705
about 2 years to finish those loops. Even if your cpu is twice as fast as mine (and mine is not that terribly slow) this is still about one year. I suppose if you have the parallel computing toolbox, and 12 fast cores to run on, you might get it down to a month of CPU time, running flat out. And one melted down computer.
And of course, it is likely that no combination will give you an exactly zero result.
And worse, the determinant is a terrible way to test for singularity of a matrix. So even if you get an approximately zero result, you won't be sure of the singularity.
Far more intelligent in terms of the numerics would be to minimize the negative of the condition number of the matrix.
help cond
A condition number that exceeds 1e15 or so is a good indication of a singular matrix.
By the way, don't forget either that while X, Y, J, and K all look to be scaled to be in terms of degrees, that sin and cos are defined in terms of radians.
Finally, there will surely be infinitely many solutions, if there are any solutions at all to this problem. You probably won't find any of them using your loops though. And any minimization scheme will give you only an isolated solution, not the set of infinitely many possible solutions.
I'll stop here, but you might reconsider the approach you seem to be taking with this problem.
  3 Comments
John D'Errico
John D'Errico on 11 May 2015
I'll start writing that book just after my computer finishes with that long set of loops.
John D'Errico
John D'Errico on 11 May 2015
Just for kicks...
condA = @(X,Y,J,K,L,M) cond(
[cosd(X).*cosd(Y) sind(J).*cosd(K) -sind(X).*sind(K);
L+cosd(J) L.*M.*sind(Y) M.*sind(K);
M.*sind(X).*sind(Y) L.*cosd(X) M.*sind(Y).*sind(K)]);
Pick some random numbers for 4 of the parameters:
J = rand*6 - 3
K = rand*14
L = 1200 + rand*(11000 - 1200)
M = 35000 + rand*(44000 - 35000)
J =
-0.71065
K =
10.717
L =
8993
M =
36682
Plot what remains as a surface. Note that cond(A) needs to be at least on the order of magnitude of 1e15 before we will consider that A is singular. (det is USELESS here.)
ezsurf(@(X,Y) condA(X,Y,J,K,L,M),[-10,10],[-35,35])
Note that every set of numbers for J,K,L,M that I tried, the maximum condition number happens at the corners of this plot. And for NONE of those random sets did the condition number ever exceed 1e8 or so.

Sign in to comment.


Walter Roberson
Walter Roberson on 11 May 2015
As an optimization, you can take the symbolic determinant and do simplification on it. With little symbolic effort it comes out as
(L .* M.^2 * (cos(X) .* cos(Y) + sin(X).^2) .* sin(Y).^2 + sin(J) .* M .* cos(K) .* (M .* sin(X) - L - cos(J)) .* sin(Y) - L .* cos(X) .* (cos(Y) .* M .* cos(X) + sin(X) .* (L + cos(J)))) .* sin(K)
which is a form you could use in combination with ndgrid() to try a number of combinations at one time.
One of the bits that sticks out is that the whole is multiplied by sin(K) so the determinant will be 0 for every combination in which K=0. Likewise for all the non-zero K you can omit the * sin(K) as you know that is going to be a non-zero multiplier on something that is going to have to be 0 itself if you are to end with a determinant of 0.
You can also see by examination that any solution is going to have to be by a whole series of identities if it is to work at all. You might certainly cross zero in the determinant but you are seldom going to get 0 exactly as long as you are using discrete variables.
It seems likely to me that you don't really want discrete variables, that you want to find the zeros within those bounds. To do that you should be considering a method such as patternsearch() . Or if you are willing to remove the constraints, you could use fminunc(), possibly specifying a user gradient function.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!