I tried to use Star Strider ‘Igor_Moura’ function to solve same problem adding another one ode equation (without experimental data, just need to solve), but i have problem:
function C=kinetics(theta,t)c0=[1;0;0;0;0];[T,Cv]=ode45(@DifEq,t,c0);%
function dC=DifEq(t,c) dcdt=zeros(5,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); dcdt(5)=theta(1).*c(2)-theta(5); dC=dcdt; endC=Cv;end
So, I just added 5th equation, for example:
dcdt(5)=theta(1).*c(2)-theta(5)
I assuemd that there is no experimental data for 5th equation, and i just have to solve this equation.
I change nothing in script.
t=[0.10.20.40.60.811.523456];c=[0.902 0.06997 0.02463 0.002180.8072 0.1353 0.0482 0.0081920.6757 0.2123 0.0864 0.02890.5569 0.2789 0.1063 0.062330.4297 0.3292 0.1476 0.097560.3774 0.3457 0.1485 0.12550.2149 0.3486 0.1821 0.25260.141 0.3254 0.194 0.34010.04921 0.2445 0.1742 0.52770.0178 0.1728 0.1732 0.63230.006431 0.1091 0.1137 0.77020.002595 0.08301 0.08224 0.835]; theta0=[1;1;1;1;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))endtv = linspace(min(t), max(t));Cfit = kinetics(theta, tv);figure(1)plot(t, c, 'p')hold onhlp = plot(tv, Cfit);hold offgridxlabel('Time')ylabel('Concentration')legend(hlp, 'C_1(t)', 'C_2(t)', 'C_3(t)', 'C_4(t)', 'Location','N')
And i get this:
Error using lsqcurvefit (line 251)
Function value and YDATA sizes are not equal.
Error in script (line 28)
[theta,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(@kinetics,theta0,t,c);
I would really appreciate the help.
Thanks in advance,
Best Answer