"Bjorn Gustavsson" <
bj...@irf.se> wrote in message <kngshj$8ta$
1...@newscl01ah.mathworks.com>...
I did try ode23s thinking along the same line as you but it did really help. What actually works (partially) is that I made "param" a global variable. Then lsqnonlin was able to call fit_simp.m.
However lsqnonlin did not do what it is intend to, ie. to optimize/ or fit to the data t,x supplied while varying the param. I see 6 iterations that lsqnonlin call fit_simp.m and every iteration did nothing but just print the supplied parameters. At the 6th iteration lsqnonlin basically give up, I am thinking of changing the lsqnonlin stopping criteria. Any suggestions?
"Initial point is a local minimum.
Optimization completed because the size of the gradient at the initial point
is less than the default value of the function tolerance."
here's my latest fit_simp.m
function diff = fit_simp(param,t,x)
global kf1 kr1 kfd1 krd1 kf2 param
kf1=param(1);
kr1=param(2);
kfd1=param(3);
krd1=param(4);
kf2=param(5);
% param(1)=kf1;
% param(2)=kr1;
% param(3)=kfd1;
% param(4)=krd1;
% param(5)=kf2;
tspan=0:0.1:100;
init = [2 2 0.0015 0.0005 0.1];
% options = odeset('RelTol',1e-3,'AbsTol',[1e-6 1e-6 1e-6 1e-6 1e-6]);
[t,y]=ode45(@myeqn, tspan, init);
save('test');
diff = y(:,5);
figure;plot(t,y(:,5),'g',t,x,'r');