How to do curve fitting with differential equation?

I have a differential equation as,
dotn(1) = -k_rs*n(1)-k_ISC*n(1)-k_SS*n(1)^2-k_ST*n(1)*n(2)+0.25*k_TT*n(1)^2;
Here k_SS, k_TT and k_ST is unknown (my plan is to get them from experimental data by fitting)
I want to fit this equation into n(1) vs time graph. Please let me know your suggestions.

Answers (1)

madhan ravi
madhan ravi on 5 Nov 2018
Edited: madhan ravi on 5 Nov 2018

2 Comments

Hi Madhan, Please have look on my code, mathematical model and experimental data (all attached
with this comment). The output are changing with each run. Also please let me know how to plot the fit curve as well.
%
clear all, close all, clc
load("CBP4czEx37213us")
Time = CBP4czEx37213us.Timens;
Sdata = CBP4czEx37213us.Decay;
%plot(Time,Sdata,'bo',Time,MonodKinetics1(B,Time),'g-')
%set(gca,'yscale','log')
B0 = rand(7,1)*100;
[B,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat] = lsqcurvefit(@MonodKinetics1,B0,Time,Sdata);
function S = MonodKinetics1(B,t)
IC_ns = 10000;
IC_nt = 0;
IC = [IC_ns IC_nt];
tspan = 0:3.5117:14383.75936;
function dotn = Matlabform (t,n)
% k_rs = 3.2e7; B(1)
% k_ISC = 0.15* k_rs; B(2)
% k_RISC = 5.6e2; B(3)
% k_SS = 3.5e-12; B(4)
% k_ST = 1.9e-10; B(5)
% k_TT = 2.2e-15; B(6)
% k_NRT = 8.2e2; B(7)
dotn = zeros(2,1);
dotn(1) = -B(1)*n(1)-B(2)*n(1)+B(3)*n(2)-B(4)*n(1)^2-B(5)*n(1)*n(2)+0.25*B(6)*n(2)^2;
dotn(2) = -B(3)*n(2)+B(2)*n(1)-B(7)*n(2)-1.25*B(6)*n(2)^2;
end
[t,nsol] = ode15s(@Matlabform,tspan,IC);
S = nsol(:,1);
end
Also thanks for the links in the 1st comment. I made this code based on link 1.

Sign in to comment.

Asked:

on 5 Nov 2018

Commented:

on 7 Nov 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!