Is the following algorithm to solve non-linear equations in complex variable consistent?

Dear users,
In order to solve the following equation((Z1/(ro_l*sqrt(G)))*((1-R).^2)* sqrt(1+0.25*(((ro_l*sqrt(G))/Z1)-(Z1/(ro_l*sqrt(G)))).^2*(sin(k*L)).^2) - 1=0) with respect to the complex variable G I have implemented this simple algorithm: function solveeqs()
guess=[1+i];
options = optimset('MaxFunEvals',1000000,'MaxIter',100000);
[result,fval,exit,output]=fsolve(@eqns,guess,options);
result
fval
eqns(guess)
output
end
function fcns=eqns(z)
G=z(1);
ro_s=2700; %insert density of the solid in kg/m3
cs= 3000;
Z1= ro_s*cs;
R= 0.995+i;
ro_l=1000;
om=10*10^6;
k=om/cs;
L=100*10^-6;
Z2=ro_l*sqrt(G);
fcns(1)= (Z1/Z2)*((1-R).^2) sqrt(1+0.25((Z2/Z1)-(Z1/Z2)).^2*(sin(k*L)).^2) - 1;
end
the result is the following:
Optimizer appears to be converging to a minimum that is not a root: Sum of squares of the function values is > sqrt(options.TolFun). Try again with a new starting point.
result =
2.7429e+004 -3.8961e+003i
fval =
-0.0182 - 0.0192i %result at last iteration
ans =
-5.2902e+003 +2.1171e+003i % first iteration result with guess value
output =
iterations: 78
funcCount: 158
algorithm: 'trust-region dogleg'
firstorderopt: 8.8405e-007
message: [1x169 char]
The message error rises because the solution obtained at the last iteration (the 78th) is of the order of magnitude 1 while this algorithm is consistent with a solution of the order of 10^-6. The doubt I have is: do you think this algorithm is consistent? working with complex number in fact I fear that matlab is not able to find a solution closer to the 0.
Is there a better way to threat this problem? (any other function or algorithm to threat with complex variable would be really usefull).

 采纳的回答

I don't think FSOLVE supports complex-valued functions/variables and am amazed it ran without errors. This recent thread looks closely related
and suggests an alternative.

4 个评论

Matt, thank you for the link, I think that's the best way to solve my problem; the only thing is that I don't understand what you did in the second line of that code: can you explain it to me? What if I want to solve a system of complex coupled equation?
The second line was
c=@(x) complex(x(1),x(2));
This just creates a single-argument alias for the COMPLEX command. c([a,b]) converts the vector [a,b] to the complex number a+b*i
For a system of equations, I would modify as follows
g =@(z) [real(z);imag(z)];
sol=c( fsolve( @(x) g(c(f(x))), x0) )
Dear Matt,
I think there is small problem with the last line of the code. "sol=c( fsolve( @(x) g(c(f(x))), x0) )"
It should rather be sol=fsolve( @(x) g(c(f(x))), x0) can you please check to confirm.
Thanks
kaust,
If you don't feed the output of fsolve to c(), then your final result will not be a complex variable.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by