
How can I graph a nonlinear system of differential equations?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Sam Chak
le 12 Juin 2022
I don't know how your graphs are supposed to look like because I'm not an adiabatic pistonist. But first things first, you must verify if your differential equations are 100% correct. I have made the substitutions and simplified them, so please check them.
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);
dTdt = - v.*(p/p_i)*a;
dydt = [dxdt; dvdt; dTdt];
end
One mistake is spotted though. To plot the pressure p, which is a division between two vectors, you must add a 'dot' in front of the slash /.
x = y(:,1);
v = y(:,2);
temp = y(:,3);
p = p_i*(temp./x);
figure(1)
plot(t, p)
title('pressure vs time')

Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

