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!
