Hello, I'm new to Matlab. I would like to fit two parameters used in differential equations by using lsqnonlin. The idea is to find the parameters by minimising the difference between the experimental curve and the generated curve. I tried to minimize the ssq between the two curves but if you look at the graphs it seems that Matlab somehow takes a wrong average of the difference between the two curves.
The code (one function and one script)looks like this:
clear;clc;
global rate;
load('rate');
k0=[0.04,0.02];
[x]=lsqnonlin(@kin4,k0);
[a,b]=kin4(x);
subplot(3,1,1), plot(rate);
subplot(3,1,2), plot(b);
subplot(3,1,3), plot(a);
function [r,y] = kin4( k)
global rate;
n=size(rate,1);
[t,y] = ode23s(@kin2,[300/n:300/n:300],[0.1,0.0]);
r=times((rate-y),(rate-y));
function dy=kin2(t,y)
dy = zeros(2,1);
dy(1) = -k(1)*y(1);
dy(2) = k(1)*y(1)-k(2)*y(2);
end
end
0 Comments
Sign in to comment.