Skip to main content
Added addendum
Source Link
Michael E2
  • 244.7k
  • 18
  • 350
  • 774

Re: Additional request for simplification.

Put the ReplaceAll (/.) outside the list of things to plot. It will, after all, replace all instances of Paorta. :)

Manipulate[Plot[
  Evaluate[
   {Paorta[t],
    (1/2*k*(1 + Cos[ω t]) + 10),
    (((1/2*k*(1 + Cos[ω t]) + 10) - Paorta[t])/Ro)
   } /. NDSolve[{Paorta'[t] == 
       1/Caorta ((1/2*k*(1 + Cos[ω t]) + 10 - Paorta[t])/
           Piecewise[{{Ro, 1/2*k*(1 + Cos[ω t]) + 10 - Paorta[t] > 0}}, 
            x*Ro] - Paorta[t]/Rsystemic), 
      Paorta[0] == 90}, {Paorta[t]}, {t, 0, 10}]
   ],
  {t, 0, 10}, ImageSize -> Large, PlotRange -> Full, 
  PlotLegends -> {"Aortic Pressure", "Pressure in Left Ventricle", "Flow"}],
 {{Caorta, 1/.48}, 1, 6},
 {{Rsystemic, 3.1}, .1, 6},
 {{x, 8000}, 1, 10000},
 {{ω, 2 π}, π, 3 π},
 {{k, 110}, 60, 200},
 {{Ro, .01}, .007, .05}]

Re: Additional request for simplification.

Put the ReplaceAll (/.) outside the list of things to plot. It will, after all, replace all instances of Paorta. :)

Manipulate[Plot[
  Evaluate[
   {Paorta[t],
    (1/2*k*(1 + Cos[ω t]) + 10),
    (((1/2*k*(1 + Cos[ω t]) + 10) - Paorta[t])/Ro)
   } /. NDSolve[{Paorta'[t] == 
       1/Caorta ((1/2*k*(1 + Cos[ω t]) + 10 - Paorta[t])/
           Piecewise[{{Ro, 1/2*k*(1 + Cos[ω t]) + 10 - Paorta[t] > 0}}, 
            x*Ro] - Paorta[t]/Rsystemic), 
      Paorta[0] == 90}, {Paorta[t]}, {t, 0, 10}]
   ],
  {t, 0, 10}, ImageSize -> Large, PlotRange -> Full, 
  PlotLegends -> {"Aortic Pressure", "Pressure in Left Ventricle", "Flow"}],
 {{Caorta, 1/.48}, 1, 6},
 {{Rsystemic, 3.1}, .1, 6},
 {{x, 8000}, 1, 10000},
 {{ω, 2 π}, π, 3 π},
 {{k, 110}, 60, 200},
 {{Ro, .01}, .007, .05}]
Source Link
Michael E2
  • 244.7k
  • 18
  • 350
  • 774

You've got Evaluate in the wrong place. It has to be of the form

Plot[Evaluate[stuff to plot...],...]

So this seems to work:

Manipulate[
 Plot[Evaluate@{
   (ReplaceAll[Paorta[t], 
      NDSolve[{Paorta'[t] == 
         1/Caorta ((1/2*k*(1 + Cos[ω t]) + 10 - Paorta[t])/
             Piecewise[{{Ro, 
                1/2*k*(1 + Cos[ω t]) + 10 - Paorta[t] > 0}}, 
              x*Ro] - Paorta[t]/Rsystemic), 
        Paorta[0] == 90}, {Paorta[t]}, {t, 0, 10}]]),
    (1/2*k*(1 + Cos[ω t]) + 10),
    (((1/2*k*(1 + Cos[ω t]) + 10) - 
        ReplaceAll[Pao[t], 
         NDSolve[{Pao'[t] == 
            1/Caorta ((1/2*k*(1 + Cos[ω t]) + 10 - Pao[t])/
                Piecewise[{{Ro, 1/2*k*(1 + Cos[ω t]) + 10 - Pao[t] > 0}}, 
                 x*Ro] - Pao[t]/Rsystemic), 
           Pao[0] == 90}, {Pao[t]}, {t, 0, 10}]])/Ro)}, {t, 0, 10}, 
  ImageSize -> Large, PlotRange -> Full, 
  PlotLegends -> {"Aortic Pressure", "Pressure in Left Ventricle", "Flow"}],
 {{Caorta, 1/.48}, 1, 6},
 {{Rsystemic, 3.1}, .1, 6},
 {{x, 8000}, 1, 10000},
 {{ω, 2 π}, π, 3 π},
 {{k, 110}, 60, 200},
 {{Ro, .01}, .007, .05}]

Plot has the attribute HoldAll. Evaluate overrides holding an argument exactly when it is the Head of the argument. That's why the placement is important.