Solve a system of four differential equations with experimental values of one dependent variable.

3 次查看(过去 30 天)
Hi everyone,
On the code below, is it posible to solve a system of four differential equations with experimental values of one dependent variable? The code runs well when I solve one ODE.
function Igor
% 2016 12 03
% NOTES:
%
% 1. The ‘theta’ (parameter) argument has to be first in your
% ‘kinetics’ funciton,
% 2. You need to return ALL the values from ‘DifEq’ since you are fitting
% all the values
function C=kinetics(theta,t)
%c0=[1;0;0;0];
c0=[1];
[T,Cv]=ode45(@DifEq,t,c0);
%
function dC=DifEq(t,c)
% dcdt=zeros(4,1);
dcdt=zeros(1,1);
dcdt(1)=-theta(1).*c(1)-theta(2).*c(1);
% dcdt(2)= theta(1).*c(1)+theta(4).*c(3)-theta(3).*c(2)-theta(5).*c(2);
% dcdt(3)= theta(2).*c(1)+theta(3).*c(2)-theta(4).*c(3)+theta(6).*c(4);
% dcdt(4)= theta(5).*c(2)-theta(6).*c(4);
dC=dcdt;
end
C=Cv(:,:);
end
t=[0.1
0.2
0.4
0.6
0.8
1
1.5
2
3
4
5
6];
c=[0.902
0.8072
0.6757
0.5569
0.4297
0.3774
0.2149
0.141
0.04921
0.0178
0.006431
0.002595];
% theta0=[1;1;1;1;1;1];
theta0=[1;1];
[theta,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@kinetics,theta0,t,c);
fprintf(1,'\tRate Constants:\n')
for k1 = 1:length(theta)
fprintf(1, '\t\tTheta(%d) = %8.5f\n', k1, theta(k1))
end
tv = linspace(min(t), max(t));
Cfit = kinetics(theta, tv);
figure(1)
plot(t, c, 'p')
hold on
hlp = plot(tv, Cfit);
hold off
grid
xlabel('Time')
ylabel('Concentration')
% legend(hlp, 'C_1(t)', 'C_2(t)', 'C_3(t)', 'C_4(t)', 'Location','N')
end
Thanking you in advance.

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by