MATLAB Answers

How do I plot my differential equation on Matlab?

3 views (last 30 days)
Francine Punzalan
Francine Punzalan on 2 Aug 2021
Answered: Star Strider on 2 Aug 2021
Here is my MATLAB code.
syms v(t) t C1
inflow = 3
peri = .4
Vin = 40
outflow = 4
p = .3
qip = p*inflow
p2 = (v)/(Vin+(inflow-outflow)*(t))
qop = p2*outflow
eqn = diff(v) == qip-qop
S = dsolve(eqn);
pretty(S)
Vp = Vin*peri;
tval = 0;
D = Vp-S
Value = subs(D,tval)
C1 = solve(Value)
tval2 = 7;
Value2 = subs(D,tval2)
C2 = solve(Value2)
V = p*(Vin-tval2)+C1*(Vin-tval2)^(4)
I'm trying to plot Vp and V, but whenever I do, the figure just shows a straight line. It should be something like (tval,Vp) and (tval2,V). Please help, thank you!

Answers (1)

Star Strider
Star Strider on 2 Aug 2021
Of copurse it’s going to be a straight line!
After evaluating the functions, look at ‘(tval,Vp)’ and ‘(tval2,V)’. They are all constants!
syms v(t) t C1
inflow = 3
inflow = 3
peri = .4
peri = 0.4000
Vin = 40
Vin = 40
outflow = 4
outflow = 4
p = .3
p = 0.3000
qip = p*inflow
qip = 0.9000
p2 = (v)/(Vin+(inflow-outflow)*(t))
p2(t) = 
qop = p2*outflow
qop(t) = 
eqn = diff(v) == qip-qop
eqn(t) = 
S = dsolve(eqn);
pretty(S)
4 3 t C1 (t - 40) - --- + 12 10
figure
fsurf(S, [-5 5 0 75])
xlabel('Initial Condition')
ylabel('t')
Vp = Vin*peri
Vp = 16
tval = 0;
D = Vp-S
D = 
Value = subs(D,tval)
Value = 
C1 = solve(Value)
C1 = 
tval2 = 7;
Value2 = subs(D,tval2)
Value2 = 
C2 = solve(Value2)
C2 = 
V = p*(Vin-tval2)+C1*(Vin-tval2)^(4)
V = 
.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!