Group Abstract Group Abstract

Message Boards Message Boards

Plot one dependent variable against another?

Posted 10 years ago

I am trying to solve for temperature, pressure and volume of a gas chamber under piston containing real gas, subjected to compression and heat transfer. I am solving a single ODE for temperature (y1[t]) where time is an independent variable, given the velocity of the piston. I prescribe the piston displacement as a function of time. I am computing pressure as a dependent variable based on the solution of the ODE and I can plot temp vs time and vol vs time. But now I would like to plot pressure vs volume change. I am having a hard time figuring out how to accomplish this. I would appreciate any help or suggestion. Below is the code.

Clear["Global`*"];
\[Rho]0 = 1.25; \[Rho] = 140*\[Rho]0; M = 28.013; v = M/\[Rho];
tp = 10;
f = .2; \[Omega] = 2 \[Pi] f; V0 = 50; mg = 
 V0*10^-3*\[Rho]; Cv = .743; D0 = 250 10^-3; L = 2; Aw = \[Pi] D0 L;
h = 200/Aw;
\[Tau] = (mg Cv)/(h Aw) 10^-3;
Tw = 300;
R = 8.314;
a = 2.54; A0 = 106.73; b = .002328; B0 = .04074; c = 7.379 10^4; C0 = 
 8.164 10^5; \[Alpha] = 1.272 10^-4; \[Gamma] = .0053;
disp = 25 (1 - Cos[\[Omega] t]); vel = D[disp, t];

sol = NDSolve[{y1'[t] - (Tw - y1[t])/\[Tau] + 
      1/Cv ((R y1[t])/v (1 + b/v^2) + 
         1/v^2 (B0 R y1[t] + 2 C0/(y1[t])^2) - (2 c)/(
          v^3 (y1[t])^2) (1 + \[Gamma]/v^2) Exp[-(\[Gamma]/v^2)])*
       vel == 0, y1[0] == 300}, y1, {t, 0., tp}];


Temp = Evaluate[y1[t] /. sol];
Press = ((R Temp)/v + 1/v^2 (B0 R Temp - A0 - C0/(Temp)^2) + 
     1/v^3 (b R Temp - a) + 1/v^6 a \[Alpha] + 
     1/(v^3 (Temp)^2) (c (1 + \[Gamma]/v^2) Exp[-(\[Gamma]/v^2)]))  
    10^-3 ;

xlist1 = Table[t, {t, 0, tp, .1}];
ylist1 = Table[disp, {t, 0, tp, .1}];
ylist2 = Table[Press, {t, 0, tp, .1}];
mydata1 = Transpose[{ylist1, ylist2}];


ListPlot[{mydata1}, Joined -> True, Frame -> True, Axes -> True, 
 PlotRange -> Automatic, FrameLabel -> {"Vol (m3)", "Pressure (MPa)"},
  LabelStyle -> Directive[Black], GridLines -> Automatic, 
 AspectRatio -> .65, PlotStyle -> {{Purple, Thickness[0.01]}}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 15}]

Plot[{disp, vel}, {t, 0, tp}, Frame -> True, Axes -> True, 
 PlotRange -> All, FrameLabel -> {"Time (secs)", "Temperature (K)"}, 
 GridLines -> Automatic, AspectRatio -> .65, 
 PlotStyle -> {{Red, Thickness[0.0075]}, {Gray, Thickness[0.005]}}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 15}]

Plot[Temp, {t, 0, tp}, Frame -> True, Axes -> True, PlotRange -> All, 
 FrameLabel -> {"Time (secs)", "Temperature (K)"}, 
 GridLines -> Automatic, AspectRatio -> .65, 
 PlotStyle -> {{Blue, Thickness[0.005]}, {Cyan, Thickness[0.0075]}}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 15}]

Plot[Press, {t, 0, tp}, Frame -> True, Axes -> True, PlotRange -> All,
  FrameLabel -> {"Time (secs)", "Pressure (MPa)"}, 
 GridLines -> Automatic, AspectRatio -> .65, 
 PlotStyle -> {{Brown, Thickness[0.0075]}}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 15}]
POSTED BY: Kaushik Mallick
2 Replies
Posted 10 years ago

Thank you so much!

POSTED BY: Kaushik Mallick

What about ParameticPlot?

ParametricPlot[{Temp[[1]], Press[[1]]}, {t, 0, tp}, AspectRatio -> 1, ImageSize -> Large]

enter image description here

If you prefer working with lists instead of continuous functions this appears to work:

press = Flatten@ylist2;
temps = Flatten[Table[y1[t] /. sol, {t, 0, tp, .1}]];
ListLinePlot[Transpose[{temps, press}]]

enter image description here

Cheers,

M.

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard