I am trying to fit my experimental data to a model that includes 2 coupled ODEs. I've created a separate function for defining the 2 ODEs, where a
is the array that contains the 2 constants I'm trying to fit.
function dy = CalcCoupODEs(t,y,a)
%dy= matrix with all 2 ODEs
dy = zeros(2,1); % variable definition
dy(1) = 1.41.*a(1) .* ((y(2)*y(1)^2)^2)*y(1) - a(2) .* y(1)*t ; %ODE for R
dy(2) = -a(1)*(y(2)*y(1)^2)^2; %ODE for n
end
Then, I call the function in the following way:
cycle_DMACl = [20, 25, 30, 40, 45]; % this is t variable
R_DMACl = [18.34, 11.29, 7.09, 6.51, 4.396]; %this is y(1)
n_DMACl = [92.31, 61.9, 53.82, 26.04, 11.87]; % this is y(2)
a0 = [1, 1]; %initial guess for constants
lb1 = [0, 0]; %lower bound
a = lsqcurvefit(@CalcCoupODEs, a0, cycle_DMACl(:), R_DMACl(:), n_DMACl(:), lb1);
I get the following:
Warning: Length of lower bounds is >
length(x)
; ignoring extra bounds.
It's obviously not trying to fit the correct thing (a
and lb
are both 1x2). What am I doing wrong and what is the best way to do this?
Thank you!
I have little experience with lsqcurvefit(...), but a quick look at MathWork's documentation of the function leads me to think that your arguments do not match MATLAB's syntax expectations. Your usage looks like
lsqcurvefit(fun,initial_points,time,y1_data,y2_data,lower_bounds)
That's six arguments with two y data entries. The function's documentation shows a six argument syntax that reads
lsqcurvefit(fun,initial_points,time,y_data,lower_bounds,upper_bounds)
I tried a quick fix by making a new matrix,
y_data = [y1_data', y2_data']
and inserting some high-value and random upper bounds. I got an error in return.
I think you are going to have to redefine your ydata array and define upper bound values. I'll keep on playing with it and post any progress, but it might take some time. Good luck, please post a solution.