Error using fsolve or lsqnonlin
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I am trying to solve a nonlinear function but I always get an error. I've tried to use fsolve and lsqnonlin but they're both not working. Can anybody help me?
Here is the part of my code where I use fsolve/lsqnonlin
for j=1:length(c_CSB_KA)
k=100;
f_A_in=(0.35-0.2)*rand(k,1)+0.2;
f_B_in=(0.4-0.1)*rand(k,1)+0.1;
x0=[f_A_in,f_B_in];%Anfangswerte
CSB = c_CSB_KA(j);
AFS = c_AFS_KA(j);
fS = f_S(j);
iCSB = 1.6;
fCSB = 0.15;
CSB_Fraktionierung = @(x)[
AFS*iCSB*(1-x(2))*x(1);
AFS*iCSB*(1-x(2))*(1-x(1));
fCSB*(CSB*(1-fS)-AFS*iCSB*(1-x(2))*x(1));
CSB*(1-fS)-AFS*iCSB*(1-x(2))-fCSB*(CSB*(1-fS)-AFS*iCSB*(1-x(2))*x(1))
];
x= lsqnonlin(CSB_Fraktionierung,x0);
a=x';
ak(:,:,j)=a; %Parameter fA,fS in ak speichern
end
And I got this error:
Error using levenbergMarquardt (line 16)
Objective function is returning undefined values at initial point. lsqnonlin cannot continue.
Error in lsqncommon (line 175)
levenbergMarquardt(funfcn,xC,flags.verbosity,options,defaultopt,initVals.F,initVals.J, ...
Error in lsqnonlin (line 253)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,allDefaultOpts,caller,...
Error in Monte_Carlo (line 76)
x= lsqnonlin(CSB_Fraktionierung,x0);
Thank you for your help! :)
9 Commenti
Adam Danz
il 23 Ago 2018
Modificato: Adam Danz
il 23 Ago 2018
If it works in the command line but not when running the code, use the debug tool to stop the code just before executing the problematic lines and make sure the input values are as you expect them to be (they probably aren't). Then you can work your way backwards to see what's going on. This is the art of debugging (which you may already know) and once you get the hang of it, you'll become a hero.
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!