How to find a complex root from the determinate of a matrix?
2 views (last 30 days)
Show older comments
Hi everyone,
Im having a trouble that can be described into two steps:
1)Im having a square complex matrix with unknown x.
2)I need to find x such that the determine of the matrix is zero.
Im trying to separate the solution into real and imag part and solve:
Function detM = detMcal(x,a,delta,L)
complexX = complex(x(1:2:end), x(2:2:end));
complexY = det(Matrix(x,a,delta,L))
detM = [real(complexY); imag(complexY)];
end
and
x = fsolve(@(x) detMcal(x,a,delta,L),[1,1]);
solution = complex(x(1:2:end), x(2:2:end))
But the program is not working. Is my code wrong or are there any better method?
Many Thanks.
0 Comments
Answers (2)
Dr. Seis
on 8 Feb 2012
Here is another example:
>>a = complex(randn(1),randn(1));
b = complex(randn(1),randn(1));
c = complex(randn(1),randn(1));
d = complex(randn(1),randn(1));
e = complex(randn(1),randn(1));
f = complex(randn(1),randn(1));
g = complex(randn(1),randn(1));
i = complex(randn(1),randn(1));
>> x = fsolve(@(x)det([a,b,c;d,e,f;g,x,i]),0)
Optimization terminated: first-order optimality is less than options.TolFun.
x =
-2.1461 - 1.9256i
>> M = [a b c; d e f; g x i];
>> det(M)
ans =
2.4603e-08 - 2.9054e-09i
>> x = (g*(b*f-c*e) + i*(a*e-b*d))/(a*f-d*c)
x =
-2.1461 - 1.9256i
>> M = [a b c; d e f; g x i];
>> det(M)
ans =
-1.0025e-15 - 5.6272e-16i
Clearly, the version that does not use "fsolve" is giving an answer that is closer to 0. However, setting the "TolFun" to something different will allow "fsolve" to run more iterations and converge to a more optimal solution. Obviously you wouldn't actually have to define "a" through "i" and construct a matrix as I did above, you would just define the matrix with all of its complex values and then stick an "x" for the element you want to solve for. Or are you planning on reading in these values from another source?
3 Comments
Dr. Seis
on 8 Feb 2012
"fzero" will probably work, but is designed more for a different application. As far as what the error is, can you provide an example of what "bta", "a", "delta", "L" and/or the result of "Matrix(bta,a,delta,L)" would be?
I guess I am unsure of what you are doing when you break up the problem into real and imaginary parts since if you had a complex matrix "A", then det(A) does not necessarily equal det(real(A)) + i*det(imag(A))
Dr. Seis
on 7 Feb 2012
You are trying to do the following, but for almost any MxM matrix and any location of x within that matrix:
Example:
M = [a b c; d e f; g x i];
We need -
0 = det(M) = g*(b*f-c*e) - x*(a*f-d*c) + i*(a*e-b*d)
Done at the command line -
>> a = complex(randn(1),randn(1));
>> b = complex(randn(1),randn(1));
>> c = complex(randn(1),randn(1));
>> d = complex(randn(1),randn(1));
>> e = complex(randn(1),randn(1));
>> f = complex(randn(1),randn(1));
>> g = complex(randn(1),randn(1));
>> i = complex(randn(1),randn(1));
>> x = (g*(b*f-c*e) + i*(a*e-b*d))/(a*f-d*c);
>> M = [a b c; d e f; g x i]
M =
2.7694 + 0.1576i 3.0349 + 0.9572i -0.0631 + 0.8003i
-0.2050 + 0.4218i 1.4897 + 0.7922i 1.4172 + 0.6557i
-1.2075 + 0.8491i 0.6899 + 1.2400i 1.6302 + 0.6787i
>> det(M)
ans =
3.3931e-15 - 3.7396e-16i
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!