How to encounter errors like 'Solver stopped prematurely' and 'Failure in initial objective function evaluation. FSOLVE cannot continue.'?
显示 更早的评论
I got these errors while solving two sets of coupled complex nonlinear equations. Please help?
i=sqrt(-1);
Lp=4;
l=1;
N=1e5;
g=10*1e6;
del_a=1*1e9;
U0=1*1e3;
del=0;
G=1*1e6;
dl=170;
gamma0=1*1e6;
gamma=25*1e6;
w1=42;
w2=382;
w_c=1*1e15;
h_bar=1.0546e-34;
p_in=100*1e-6;
eta=sqrt(p_in*gamma/(h_bar*w_c));
F=@(y)[y(1)+(G/w1)*abs(y(1))^2;
y(2)+(G/w2)*abs(y(1))^2;
i*y(3)*(del-G*(y(1)+y(2)))-y(3)*gamma0/2+eta];
y0=[1e-10;2;1e5];
[y,fval]=fsolve(F,y0);
X_cs=y(1);
X_ds=y(2);
a_s=y(3);
w=100;
d1=w^2-i*gamma*w-w1^2;
d2=w^2-i*gamma*w-w2^2;
d3=i*(del-w-G*(X_cs+X_ds))-gamma0/2;
Fw=@(x)[x(1)*w^2-i*gamma*w-w1^2-2*w1*G*a_s*x(3);
x(2)*w^2-i*gamma*w-w2^2-2*w2*G*a_s*x(3);
x(3)*(i*(del-w-G*(X_cs+X_ds))-gamma0/2)-i*G*a_s(x(1)+x(2))];
x0=[1;1;1];
sol=fsolve(Fw,x0);
回答(1 个)
Stephan
2018-7-15
Hi,
i can only give you about 1.5 answers of the 2 you asked:
Answer on sub-question 1.
In your function F (x) there is an error:
Fw = @ (x) [x (1) * w ^ 2-i * gamma * w-w1 w1 ^ 2-2 * * G * * a_s x (3); ...
x (2) * w ^ 2-i * w * gamma-w2 ^ 2-2 * w2 * G * a_s * x (3); ...
x (3) * (i * (del-w-G * (X_cs + X_ds)) - gamma0 / 2) -i * G * a_s (x (1) + x (2))];
The last expression:
i * G * a_s (x (1) + x (2))];
indicates that the element of a_s is to be accessed at the index (x (1) + x (2)). But a_s is a complex number - namely the solution y (3) of the first system F (y) and x(1) und x(2) are also complex numbers. If you fix this error (I suspect a '*' or '/' is missing), the script will run without error messages.
This was the reason for the message:
Error in
solve_sys_nonl_equa> @ (x) [x (1) * w ^ 2-i * gamma * w-w1 w1 ^ 2-2 * * G * * a_s x (3) x (2) * w ^ 2-i * gamma * W ^ 2-2 * w2 w2 * G * a_s * x (3) x (3) * (i * (del-wG * (X_cs + X_ds)) - gamma0 / 2) -i * G * a_s (x (1) + x (2))]
Error in fsolve (line 242)
fuser = feval (five {3}, x, varargin {:});
Error in solve_sys_nonl_equa (line 42)
[X, fx_val] = fsolve (Fw, x0, options)
Caused by:
Failure in initial objective function evaluation.
FSOLVE can not continue.
0.5 answer to sub-question 2
As far as the other part of your question is concerned, I myself am too little expert to give you good advice. I assume that the results of your calculations are probably not useful, as the solver's messages point to this. The exact reason and possible countermeasures I can not give you with my knowledge.
Maybe you are lucky and another forum member here that has better knowledge about this issue gives a god advice.
If not, my suggestion is, to run the corrected script (you should have a critical view to the results) and see if you can get better results by using different options via
optimoptions
If not, come back (e.g. with a new question) to get suggestions from the experts here. If so, give as precisly as possible what you get and what you tried.
Best regards
Stephan
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!