# 3 Differential equation using 4th order runge kutta

24 views (last 30 days)
Yinka Olatunji on 27 Oct 2021
Commented: Bjorn Gustavsson on 28 Oct 2021
Hi, pls how do i solve a three coupled differential equations using 4th order runge kutta? My area is in advanced kinetics and it seams the invoke ode 45 is for two differential eqn.How do I change it to 3??
Yinka Olatunji on 28 Oct 2021
Secondly, for the 3 coupled ode, i have this
function diffeqs=ode_sys(z,var)
z=var(1);
x1=var(2);
x2=var(3);
Te=1302;%degree Rankine
diffeqs(1,1) = (1201.6592 +(96705.4341.*((0.8-x1-x2).*(0.2-x1-x2))./(1-x2).^2)+((2359.5424.*(0.8-x1-x2).*(0.2-x1-x2))./(1-x2).^2))./7.4; %dt/dz
diffeqs(2,1) = 0.0287*(824000.*exp(-13737.37/Te).*(((0.8-x1-x2).*(0.2-x1-x2))./(1-x2).^2)); %dx1/dz
diffeqs(3,1) = 0.0287.*(46.8.*exp(-3464.65/Te).*(((0.8-x1-x2).*(0.2-x1-x2))./(1-x2).^2)); %dx2/dz
end
and my script goes thus,
% script
range=[1:11];
ICs=[4,0,0]; %initial cond
[zsol,varsol]=ode45(@ode_sys,range,ICs);
the values I obtained for z are too large and seems incorrect.Can anyone spot any mistake in my eqns?
my "varsol" result are in 3 column. How do i compute the command of "fprint" to put them in a table?
I willreally appreciate any help.

Bjorn Gustavsson on 28 Oct 2021
Edited: Bjorn Gustavsson on 28 Oct 2021
You have a function for a 2-D system of ODEs. That then is messed up:
function diffeqs =ode_Q10(t,var)
% t = var(1); % This overwrites the value of the independent input-variable t.
% does this mean that you have some other differential equation
% in a variable "T" (just to differentiate if from the
% time-variable "t")? If so then lets introduce it here:
T = var(1);
Xe = var(2);
Te=var(3);
tht = 300;
ko = 4.48e6;
E = 62800;
Rg = 8.314;
Tf = 298;
cf = 3;
Hxn = -2.09e8;
De = 1000;
cp = 4190;
diffeqs(1,1) = sin(t)*T; % Here you better insert the ODE for the "T" variable.
diffeqs (2,1) = (-Xe./tht) + ko.*exp(-E./(Rg.*Te)).*(1-Xe); %dxe/dt
diffeqs(3,1) = ((Tf-Te)./tht) - cf.*(Hxn./De.*cp).*ko.*exp(-E./(Rg.*Te)).*(1-Xe); %dTe/dt
end
This way you will now have a function for 3 ODEs for dT/dt, dXe/dt and dTe/dt. This would then be integrateable with ode45.
HTH
Bjorn Gustavsson on 28 Oct 2021
Sure: on-ramp_1