Error: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
160 views (last 30 days)
Show older comments
My code has the following error:
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using
Levenberg-Marquardt algorithm instead.
> In fsolve (line 298)
In Design (line 16)
Error using levenbergMarquardt (line 16)
Objective function is returning undefined values at initial point. fsolve cannot continue.
Error in fsolve (line 397)
levenbergMarquardt(funfcn,x,verbosity,options,defaultopt,f,JAC,caller, ...
Error in Design (line 16)
neff=fsolve(TM,Nx(i));
Can anyone tell me what is wrong with my below code:
for n=0:1
lamda=1.55;
ko=2.*pi./lamda;
n1TE=1.5100;
n2TE=1.4900;
n4TE=1.4444;
Nx=1.4900:0.0001:1.5100; % as n2<refractive index<n1
b=((n.*pi+atan(sqrt(Nx.^2-n2TE.^2)./sqrt(n1TE.^2-Nx.^2))+atan(sqrt(Nx.^2-n4TE.^2)/sqrt(n1TE.^2-Nx.^2)))./(ko.*sqrt((n1TE.^2-Nx.^2))));
for m=0:1
a=b;
n3TM=1.4895;
n5TM=1.4895;
TM=@(neff) 2.*ko.*a.*sqrt(Nx.^2-neff.^2)-m.*pi-atan((sqrt(neff.^2-n3TM.^2)./sqrt(Nx.^2-neff.^2)).*(Nx.^2./n3TM.^2))-atan((sqrt(neff.^2-n5TM.^2)./sqrt(Nx.^2-neff.^2)).*(Nx.^2./n5TM.^2));
neff=fsolve(TM,Nx);
plot(b,neff)
end
end
0 Comments
Answers (3)
Stephan
on 7 Mar 2019
Edited: Stephan
on 7 Mar 2019
Hi,
add this line before you call fsolve:
opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');
Then in your call of fsolve add the options:
neff = fsolve(TM,Nx,opts)
Best regards
Stephan
3 Comments
Stephan
on 7 Mar 2019
For me it works. try:
clear Nx
You have some more problems i guess - try:
n=[0 1];
lamda=1.55;
ko=2.*pi./lamda;
n1TE=1.5100;
n2TE=1.4900;
n4TE=1.4444;
Nx=1.5; % as n2<refractive index<n1
b=((n.*pi+atan(sqrt(Nx.^2-n2TE.^2)./sqrt(n1TE.^2-Nx.^2))+atan(sqrt(Nx.^2-n4TE.^2)/sqrt(n1TE.^2-Nx.^2)))./(ko.*sqrt((n1TE.^2-Nx.^2))));
m = [0 1];
a=b;
n3TM=1.4895;
n5TM=1.4895;
TM=@(neff,m) 2.*ko.*a.*sqrt(Nx.^2-neff.^2)-m.*pi-atan((sqrt(neff.^2-n3TM.^2)./sqrt(Nx.^2-neff.^2)).*(Nx.^2./n3TM.^2))-atan((sqrt(neff.^2-n5TM.^2)./sqrt(Nx.^2-neff.^2)).*(Nx.^2./n5TM.^2));
neff = nan(1,numel(m));
for k = 1:numel(m)
neff(k)=fsolve(@(neff)TM(neff,m(k)),Nx);
end
scatter(b,neff,'or')
hold on
plot(b,neff)
hold off
Ill ch
on 2 Oct 2019
Hi Areez,
i think there are problem with your function. Could you post here your mathematical function on which you want to fit your data? try even this one:
opts = optimoptions(@fsolve,'Algorithm', 'levenberg-marquardt');
clear Nx
n=[0 1];
lamda=1.55;
ko=2.*pi./lamda;
n1TE=1.5100;
n2TE=1.4900;
n4TE=1.4444;
Nx=1.5; % as n2<refractive index<n1
b=((n.*pi+atan(sqrt(Nx.^2-n2TE.^2)./sqrt(n1TE.^2-Nx.^2))+atan(sqrt(Nx.^2-n4TE.^2)/sqrt(n1TE.^2-Nx.^2)))./(ko.*sqrt((n1TE.^2-Nx.^2))));
m = [0 1];
a=b;
n3TM=1.4895;
n5TM=1.4895;
TM=@(neff,m) 2.*ko.*a.*sqrt(Nx.^2-neff.^2)-m.*pi-atan((sqrt(neff.^2-n3TM.^2)./sqrt(Nx.^2-neff.^2)).*(Nx.^2./n3TM.^2))-atan((sqrt(neff.^2-n5TM.^2)./sqrt(Nx.^2-neff.^2)).*(Nx.^2./n5TM.^2));
neff = nan(1,numel(m));
for k = 1:numel(m)
neff(k)=fsolve(@(neff)TM(neff,m(k)),Nx,opts);
end
0 Comments
See Also
Categories
Find more on QSP, PKPD, and Systems Biology in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!