fsolve: solving complex equation with 2 variables (already split real and imag part but didn't work)

1 次查看(过去 30 天)
Dear Matlab users,
I know that fsolve didn't work for the complex value, therefore I split my function as real and imaginary value. This is my code:
function x=test(lamda,a,b,c,d,e,f,T1,T2)
z=lamda(1,:)+1i*lamda(2,:);
g=(trace(((a+z(1)*eye(3)+z(2)*b)^-1*c)'*((a+z(1)*eye(3)+z(2)*b)^-1*c)+((d+z(1)*eye(3)+z(2)*e)^-1*f)'*((d+z(1)*eye(3)+z(2)*e)^-1*f))-6);
h=(trace(((a+z(1)*eye(3)+z(2)*b)^-1*c)'*T1'*((a+z(1)*eye(3)+z(2)*b)^-1*c)*T1+((d+z(1)*eye(3)+z(2)*e)^-1*f)'*T2'*((d+z(1)*eye(3)+z(2)*e)^-1*f)*T2)-6);
x(1)=[real(g) imag(g)];
x(2)=[real(h) imag(h)];
end
a,b,c,d,e,f,T1,and T2 are matrix from previous computation. I want to find lamda 1 and lamda 2. Then I call the function using
guess=zeros(2,2);
options=optimset('Algorithm','Levenberg-Marquardt');
result=fsolve(@(lamda)test(lamda,a,b,c,d,e,f,T1,T2), guess,options);
lamda1=result(1)+sqrt(-1)*result(2);
lamda2=result(3)+sqrt(-1)*result(4);
But the variable "result" that I used to store the fsolve solution is still a complex value with second column remain the same as the initial guess. This command appear in my workspace:
"Optimizer appears to be converging to a minimum that is not a root: Sum of squares of the function values exceeds the square root of options.TolFun. Try again with a new starting point. Maximum number of function evaluations exceeded; increase options.MaxFunEvals Optimization terminated: the magnitude of the search direction is less than options.TolX Optimization terminated: no further progress can be made. Cannot generate point that reduces the sum of squares. Problem may be ill-conditioned."
Do you know any way to fix this? Thank you
Best regards, Mei Li
  2 个评论
Matt J
Matt J 2013-12-17
编辑:Matt J 2013-12-17
You need to show us your real code, or a simplification of it that actually runs. The code you've shown for test() will not run. It should be giving you errors, like in the following
>> g=1+i; x(1)=[real(g) imag(g)];
In an assignment A(I) = B, the number of elements in B and I must be the same.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2013-12-17
function x=test(lamda,a,b,c,d,e,f,T1,T2)
z=lamda(1,:)+1i*lamda(2,:);
g=(trace(((a+z(1)*eye(3)+z(2)*b)^-1*c)'*((a+z(1)*eye(3)+z(2)*b)^-1*c)+((d+z(1)*eye(3)+z(2)*e)^-1*f)'*((d+z(1)*eye(3)+z(2)*e)^-1*f))-6);
h=(trace(((a+z(1)*eye(3)+z(2)*b)^-1*c)'*T1'*((a+z(1)*eye(3)+z(2)*b)^-1*c)*T1+((d+z(1)*eye(3)+z(2)*e)^-1*f)'*T2'*((d+z(1)*eye(3)+z(2)*e)^-1*f)*T2)-6);
gh=[g;h];
x=[real(gh),imag(gh)];
end
  4 个评论
Alan Weiss
Alan Weiss 2013-12-18
Your first result is a positive, good, correct result:
Optimization terminated: relative function value changing by less than max(options.TolFun^2,eps) and sum-of-squares of function values is less than sqrt(options.TolFun).
Notice the last phrase: "...sum-of-squares of function values is less than sqrt(options.TolFun)." This means the solver converged to a solution.
You might have been confused by the phrase "Optimization terminated." You are not alone. The exit messages were updated to be much friendlier and clearer in recent releases. The fsolve messages were enhanced in R2009b.
Alan Weiss
MATLAB mathematical toolbox documentation
Mei Li
Mei Li 2013-12-20
Dear Matt J and Alan Weiss,
The result is a complex number, but the final result isn't as what I expected. I will try to check my algorithm first. Thank you for your answers.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by