How can I graph a nonlinear system of differential equations?
Show older comments
I am having trouble solving a system of non linear differential equations regarding a simple adiabatic piston. I am able to find a solution using ode45, except the graphed solution does not look like it is supposed to. The graphs are below



For whatever reason, the graphs do not oscillate symmetrically like they are supposed to. My code is below. I am sure that I have entered the equations correctly, yet every different method I use to solve the equations I get similar results. Could someone please help
p_i = 2 ;
y0 = [1 0 1] ; %initial values
tspan = [0 10] ;
[t, y] = ode45(@rate,tspan,y0) ;
x = y(:,1) ;
v = y(:,2) ;
temp = y(:,3) ;
p = p_i * (temp / x) ;
figure(1)
plot(t,p)
title('pressure vs time')
figure(2)
plot(t,temp)
title('temperature vs time')
figure(3)
plot(t,v)
title('velocity vs time')
function dydt = rate(~,y)
x = y(1);
v = y(2);
temp = y(3);
p_i = 2 ;
a = 2/5 ;
p = p_i .* (temp ./ x) ;
dxdt = v ;
dvdt = (p - 1) ./ (p_i - 1) ;
dtempdt = -v .* (p / p_i) .* a ;
dydt = [dxdt ; dvdt ; dtempdt] ;
end
Accepted Answer
More Answers (0)
Categories
Find more on Thermodynamics and Heat Transfer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

