Uncertainty in using fsolve correctly
显示 更早的评论
Hey there,
I'm trying to solve an equatation with fsolve which I have never used beforehand.
if a<=1/3
fun=@(anew) (4*anew(k)*F*(1-anew(k))-CT(k));
a0=a;
[anew(k),fval]=fsolve(fun,a0);
else
fun=@(anew1) (4*anew1*F*(1-0.25*anew1*(5-3*anew1))-CT(k));
a0=a;
[anew1,fval]=fsolve(fun,a0);
anew2=CT/(4*F*(1-0.25*anew1*(5-3*anew1)));
b=0.1;
anew(k)=b*anew2+anew1*(1-b);
anew(k)=interp1(anew(k),a0);
end
anew is so far an empty vector.
My script says that for the last loop.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
Equation solved. The sum of squared function values, r = 4.444741e-27, is less than
sqrt(options.FunctionTolerance) = 1.000000e-03. The relative norm of the gradient of r,
1.983593e-13, is less than options.OptimalityTolerance = 1.000000e-06.
Optimization Metric Options
relative norm(grad r) = 1.98e-13 OptimalityTolerance = 1e-06 (default)
r = 4.44e-27 sqrt(FunctionTolerance) = 1.0e-03 (default)
Is that something I have to be aware of? Or is that literally a statement that it has been solved?Or are these ranges showing me some errors?
Thank you in advance, cheers.
回答(1 个)
Torsten
2018-9-25
This is not an error message, but the message that "fsolve" solved your problem.
Nevertheless, you should change
if a<=1/3
fun=@(anew) (4*anew(k)*F*(1-anew(k))-CT(k));
a0=a;
[anew(k),fval]=fsolve(fun,a0);
to
if a<=1/3
fun=@(anew1) (4*anew1*F*(1-anew1)-CT(k));
a0=a;
[anew(k),fval]=fsolve(fun,a0);
Best wishes
Torsten.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!