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

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 commentaires

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.
I am sorry I apparently called another function with different input. But do you know how to separate the complex data in fsolve? I refer to

Connectez-vous pour commenter.

Réponses (1)

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 commentaires

It still results in the command:
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).
Maximum number of function evaluations exceeded; increase options.MaxFunEvals
I call the function test() inside the iteration.. When I increase the number of MaxFunEvals, it get another message:
"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). Maximum number of iterations exceeded; increase options.MaxIter."
those problems caused my simulation running for a long time. Do you know how to fix this?
What is the value of test(lambda) when the algorithm stops?
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
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.

Connectez-vous pour commenter.

Question posée :

le 17 Déc 2013

Commenté :

le 20 Déc 2013

Community Treasure Hunt

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

Start Hunting!

Translated by