The equations are:
dP(t)/dt = kn*(10-M(t))^nc + km*M(t) - ka*P(t)^2
dM(t)/dt = kp*(10 - M(t))*P(t)
P(0) = M(0) = 0
My data consists of time, t, and fiber mass, M(t), so essentially I want to solve for M(t) to fit the data. If it helps, the M(t) can generally be fit by a sigmoidal function, but I'm using these equations because I would like to obtain the constants kn, nc, km, ka, and kp. I know there are a lot of parameters which makes fitting harder... Here is the code:
function [x] = knfit(t,f)
function S = prefun(B,t)
x0 = [0 0];
[~,Sv] = ode45(@DiffEq,t,x0);
function dS = DiffEq(t,x)
dS(1,:) = B(1)*(10-x(2))^B(2) + B(3)*x(2) - B(4)*x(1)^2;
dS(2,:) = B(5)*(10-x(2))*x(1);
S = Sv(:,1);
objfcn = @(B,t) prefun(B,t);
B0 = [0.001, 2, 0.0001, 1.1, 0.00002];
x = lsqcurvefit(objfcn,B0,t,f);
The errors that I get right now are:
Matrix dimensions must agree.
Error in lsqcurvefit/objective (line 279)
F = F - YDATA;
I'm super confused because the x and y data definitely are the same dimensions. Does B0 have to be something different?
I'm pretty new at this so go easy on me! :) Thanks!