How to solve a System of First Order ODE

4 views (last 30 days)
There are two tanks T1 and T2. T1 has 100 gallons of water, T2 has 150 pounds of salt inside and has the total mass of 100 gallons of mixed water. Every minute 2 gallons of water flows into the oppoiste tank.
y1 is the amount of salt T1 tank has. y2 is the amount of salt T2 has.
I got the equation.
y'1 = -0.02y1 + 0.02y2
y'2 = 0.02y1 - 0.02y2
it says the initial value is y1(0) = 0, y2(0) = 150 (this is obvious of course)
now I dont know anything about Matlab. But I want to graph some things.. which are
1) how do I get the graph of y1 and y2?
2) how do I get the Phase Portrait graph of this?
I would really appreciate your help thanks!
  1 Comment
Jan
Jan on 19 May 2021
"I dont know anything about Matlab"
Then please read the "Getting Started" chapters of the documentation and perform Matlab's Onramp. It would be inefficient, if the forum explains, what the "=" means in "a=1".

Sign in to comment.

Accepted Answer

Girijashankar Sahoo
Girijashankar Sahoo on 19 May 2021
clc
clear all
close all
%t=[0:0.01:100];
syms y1(t) y2(t)
ode1 = diff(y1) == -0.02*y1 + 0.02*y2;
ode2 = diff(y2) == 0.02*y1 + -0.02*y2;
cond1 = y1(0) == 0;
cond2 = y2(0) == 150;
conds = [cond1; cond2];
odes = [ode1; ode2]
[y1, y2] = dsolve(odes,conds)
fplot(t,y1)
hold on
fplot(t,y2)
xlabel('t')
legend('y1','y2')

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!