Error: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.

229 visualizaciones (últimos 30 días)
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

Respuestas (3)

Stephan
Stephan el 7 de Mzo. de 2019
Editada: Stephan el 7 de Mzo. de 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 comentarios
Stephan
Stephan el 7 de Mzo. de 2019
Editada: Stephan el 7 de Mzo. de 2019
try:
Nx = 1.5;
Note that:
...fsolve uses the number of elements in and size of x0 to determine the number and size of variables that TM accepts...
Stephan
Stephan el 7 de Mzo. de 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

Iniciar sesión para comentar.


Areez Khail Memon
Areez Khail Memon el 7 de Mzo. de 2019
can not assign Nx value as it is defined as range. Is their any other way to get the value of neff from the above given equation?

Ill ch
Ill ch el 2 de Oct. de 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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by