# Solving coupled differential equations

1 view (last 30 days)
JaeSung Choi on 15 Oct 2017
Answered: Josh Meyer on 16 Oct 2017
T o solve my coupled differential equations. I made the following function
======================
function x_value = reservoir(t,y);
s1 = y(1); s2 = y(2); s3 = y(3);
p1 = y(4); p2 = y(5); p3 = y(6);
x1 = 5.45*10^(-6);
x_value = [s1; s2; s3; p1; p2; p3];
h = 0.7844; b = 5*10^(-7); e = 8.8750*10^(-2); v = 7.54; g1 = 2500; g2= 2500; g3 =2500; x1 = 5.45*10^(-6); x2 = 5.45*10^(-6); x3 = 5.45*10^(-6);
% Define constants.
Dp1 = diff(p1); Dp2 = diff(p2); Dp3 = diff(p3);
Ds1 = diff(s1); Ds2 = diff(s2); Ds3 = diff(s3);
% Generate differentiations.
diffqp1 = Dp1 == h*b*s1*(g1-p3)-(e/v)*p1;
diffqp2 = Dp2 == h*b*s2*(g2-p1)-(e/v)*p2;
diffqp3 = Dp3 == h*b*s3*(g3-p2)-(e/v)*p3;
diffqs1 = Ds1 == x1/v-h*b*s1*(g1-p3)-(e/v)*s1;
diffqs2 = Ds2 == x2/v-h*b*s2*(g2-p1)-(e/v)*s2;
diffqs3 = Ds3 == x3/v-h*b*s3*(g3-p2)-(e/v)*s3;
% Generate differential equations.
end
===========================
And to derive explicit s1~p3 values, i used the code below.
===========================
[s1, s2, s3, p1, p2, p3] = ode45(@reservoir,[0 1],[0; 0; 0; 0; 0; 0]) ===========================
But it said " While using 'ode45' there wasn't proper substitute to output parameter 'varargout{4}'
My terminal goal is to derive s1~p3 values at each t=1,2,....so on, when i want!! How can I derive this?

Josh Meyer on 16 Oct 2017
The immediate problem is that you provide too many output arguments to ode45. The components of y will be returned as columns if you just use [t,y] = ode45(...).
Once you fix that, the next issue is that y is returned as all zeros. So you need to check your equations and/or initial condition.