fsolve: solving complex equation with 2 variables (already split real and imag part but didn't work)
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Matt J
le 17 Déc 2013
Modifié(e) : Matt J
le 17 Déc 2013
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.
Réponses (1)
Matt J
le 17 Déc 2013
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
Alan Weiss
le 18 Déc 2013
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
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!