Error using fsolve or lsqnonlin

조회 수: 1 (최근 30일)
Judith Lange
Judith Lange 2018년 8월 23일
편집: Adam Danz 2018년 8월 23일
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
Judith Lange
Judith Lange 2018년 8월 23일
Okay then I am kind of stuck again :/ but thank you for your help everybody :)
Adam Danz
Adam Danz 2018년 8월 23일
편집: Adam Danz 2018년 8월 23일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Word games에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by