Error: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
154 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Stephan
2019-3-7
编辑:Stephan
2019-3-7
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 个评论
Stephan
2019-3-7
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
2019-10-2
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 QSP, PKPD, and Systems Biology 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!