1
$\begingroup$

So I am attempting to solve a differential equation which includes a differential equation (i am not sure if this why my code is giving problems). I am pretty sure that everything is as its supposed to be.

My code isn't giving any errors, but its literally just spitting back out what I put in, which makes me think its because the interpolating function thats within the NDSolve isn't evaluating correctly. Is there a way around this?

Here is my code:

Ro = .007;
Caorta = 1/.48;
k = 110;
ω = 2 π;
x = 1000000;
Rsystemic = 3.1;
Vo = 108;
Cheart = 6.67;

Fao[t_] := ((1/2*k*(1 + Cos[ω t]) + 10) - Paorta[t])/
   Piecewise[{{Ro, 1/2*k*(1 + Cos[ω t]) + 10 - Paorta[t] > 0}},
     x*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}];

NDSolve[{Vheart'[
    t] == ((1/2*k*(1 + Cos[ω t]) + 
         10) - (((Vheart[t] - Vo)*(1/2*k*(1 + Cos[ω t]) + 
             10)) + Vheart[t]/Cheart))/
     Piecewise[{{Ro, 
        1/2*k*(1 + Cos[ω t]) + 
          10 - (((Vheart[t] - Vo)*(1/2*k*(1 + Cos[ω t]) + 
                10)) + Vheart[t]/Cheart) > 0}}, x*Ro] - 
    Evaluate[Fao[t]], Vheart[0] == 108}, Vheart[t], {t, 0, 10}]

I know for a fact that the Fao[t] works fine, which is why i am not sure what my issue is.

Thanks for you help, i really appreciate it!

$\endgroup$

1 Answer 1

1
$\begingroup$

No, your Fao[ ] doesn't work as posted.

Ro = .007;
Caorta = 1/.48;
k = 110;
ω = 2 π;
x = 1000000;
Rsystemic = 3.1;
Vo = 108;
Cheart = 6.67;
m[ω_, t_]      := 1/2*k*(1 + Cos[ω t]) + 10
PaoMwt[ω_, t_] := m[ω, t] - Paorta[t]
pw[fun_]       := Piecewise[{{Ro, fun > 0}}, x*Ro]
VhMwt[ω_, t_]  := m[ω, t] - ((Vheart[t] - Vo)*m[ω, t] + Vheart[t]/Cheart)

sol = First@ NDSolve[{Paorta'[t] ==  1/Caorta (PaoMwt[ω, t]/pw@PaoMwt[ω, t] - 
                      Paorta[t]/Rsystemic), Paorta[0] == 90}, {Paorta[t]}, {t, 0, 10}];

Fao[t_] := PaoMwt[ω, t]/pw@PaoMwt[ω, t] /. sol;

sol1 = NDSolve[{Vheart'[t] ==  VhMwt[ω, t]/pw@VhMwt[ω, t] - Fao[t], 
                Vheart[0] == 108}, Vheart[t], {t, 0, 10}]

Plot[Vheart[t] /. sol1, {t, 0, 10}]  

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ Why is it necessary to separate the actual function and the solution to the DE which I need to replace when defining Fao? Just for my future reference and to better understand programming in general. $\endgroup$
    – Dinomite00
    Jun 30, 2015 at 16:42
  • $\begingroup$ And what does the command "First@" do? Sorry if these are really stupid questions, I am really trying to better understand the way mathematica works and how I can better use it $\endgroup$
    – Dinomite00
    Jun 30, 2015 at 16:43
  • 1
    $\begingroup$ @Dinomite00 C'mon, you can't show that kind of lazyness! Go and look up First[ ] in the docs! $\endgroup$ Jun 30, 2015 at 16:54
  • $\begingroup$ I did do that haha, okay maybe I asked the wrong question. I looked it up the second I saw it and didn't recognize it and I know what it does, I am not sure why it is necessary since there isn't more than one output, or not that I can see at least. When I take it out, it no longer works which is why I am a little confused $\endgroup$
    – Dinomite00
    Jun 30, 2015 at 17:00
  • $\begingroup$ @Dinomite00 chat.stackexchange.com/rooms/2234/wolfram-mathematica $\endgroup$ Jun 30, 2015 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.