Failure in initial objective function evaluation. LSQNONLIN cannot continue
이전 댓글 표시
Hello
I am trying to optimize the following ODE

Here, B is a known constant. p1 and p2 are the variables to be optimized.
So I first created function files for the function and the ode as follows.


Next I wrote the code for optimization using the 'Optimization Toolbox'.
type diffun1
a0 = 0;
B= 5000;
temp=SFOR_P3_datapts(:,1);
p=optimvar("p",2,"LowerBound",1,"UpperBound",10^20) %p is the optimization variable ( containing p1 and p2)
%minimize sum of squares of the differences between the ODE solution with parameters p and the actual values
myfcn=fcn2optimexpr(@ode1,p,temp,a0,'OutputSize',[length(temp),1])
obj=sum((myfcn-a_actual).^2);
prob=optimproblem("Objective",obj); % default is to minimize the objective function
show(prob)
p0.p=[100,10]; %Initial guess of the parameters
[p_soln,sumsq]=solve(prob,p0) %Determining the parameters such that obj fcn (sum of squares) is the minimum
But here an error message pops up.

The procedure adopted is similar to the Mathworks example "Fit ODE Problem Based"
https://in.mathworks.com/help/optim/ug/fit-ode-problem-based-least-squares.html
Any help on how to solve this error would be deeply appreciated.
Thank You
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
