# Problem with Finding Minimum of a Function Solved With NDSolve

I am trying to find the minimum of a particular function, which is solved using NDSolve. What is making it a little more complicated is that it is not the only function solved within the NDSolve and it seems as though the interaction between the two functions I am solving for is messing with finding the minimum in some way.

Here is what I mean - this is the code that I am currently using to solve for the minimum:

Ro = .007;
Rmitral = .006;
Caorta = .48;
k = 13;
ω = 2 π;
x = 100000;
Rsystemic = 3.1;
Vo = 25;
Cheart = 2.38;
Contractility[k_, ω_, t_] := 1/2*k*(1 + Cos[ω t]);
Cvc = .05 (*L/mmhg*);
Dblood = 1060 (*kg/m^3*);
g = 9.8 (*m/s^2*);
h = .397 (*this is for females in m. For males, it is .422 m*);
Vtotal = 4 (*L*);
Ctotal = .0144 (*30 times arterial compliance*);
Viliac = .001 (*m^3*);
Ciliac = 0.1;

Quiet[First@{FindMinValue[{Paorta[t], 4 < t < 10}, t]} /.

NDSolve[{Vheart'[t] == (( (Vtotal - (Dblood * g * h*Ciliac)/133.25)/
Cvc) - ((Vheart[t] - Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, ω,
t])) + (Vheart[t] - Vo)/Cheart)/
Piecewise[{{Rmitral, ( (Vtotal - (Dblood * g * h*Ciliac)/133.25)/
Cvc) - (((Vheart[t] - Vo)*(1 - (Vheart[t]/25))^2*(Contractility[
k, ω, t])) + (Vheart[t] - Vo)/Cheart) > 0}}, x*Rmitral] - (((Vheart[t] -
Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, ω, t]) + (Vheart[t] - Vo)/Cheart)
- Paorta[t])/Piecewise[{{Ro, ((Vheart[t] -
Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, ω, t])) + ((Vheart[t] -
Vo)/Cheart) - Paorta[t] > 0}}, x*Ro], Paorta'[t] ==
1/Caorta*((((Vheart[t] - Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, ω,
t]) + (Vheart[t] - Vo)/Cheart) - Paorta[t])/Piecewise[{{Ro, ((Vheart[t] -
Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, ω, t]) + (Vheart[t] - Vo)/Cheart) -
Paorta[t] > 0}}, x*Ro] - Paorta[t]/Rsystemic),
Vheart[0] == 108, Paorta[0] == 10}, {Vheart[t], Paorta[t]}, {t, 0, 10}]]


The value should be below 20 based on inspection of my plot, but it seems to be giving me the intersection point between my two functions, as shown in the picture below:

Any suggestions/tips would be greatly appreciated, my maximization seems to work fine so I dont see why this is giving me an issue now.

• Consider using WhenEvent[] instead for finding the required extremum; if you search this site you'll find examples of its use for determining roots and extrema. – J. M. is away Apr 1 '16 at 1:01
• That actually helped a lot, thanks! – Dinomite00 Apr 1 '16 at 1:46
• If you do come up with a working solution, please answer your own question. :) – J. M. is away Apr 1 '16 at 1:52

You can extract all the local minimums and maximums by extracting where the derivative becomes zero:

{sol,paortaextrm}=Reap@NDSolve[{Vheart'[t] == (( (Vtotal - (Dblood * g * h*Ciliac)/133.25)/
Cvc) - ((Vheart[t] - Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, \[Omega],
t])) + (Vheart[t] - Vo)/Cheart)/
Piecewise[{{Rmitral, ( (Vtotal - (Dblood * g * h*Ciliac)/133.25)/
Cvc) - (((Vheart[t] - Vo)*(1 - (Vheart[t]/25))^2*(Contractility[
k, \[Omega], t])) + (Vheart[t] - Vo)/Cheart) > 0}}, x*Rmitral] - (((Vheart[t] -
Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, \[Omega], t]) + (Vheart[t] - Vo)/Cheart)
- Paorta[t])/Piecewise[{{Ro, ((Vheart[t] -
Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, \[Omega], t])) + ((Vheart[t] -
Vo)/Cheart) - Paorta[t] > 0}}, x*Ro], Paorta'[t] ==
1/Caorta*((((Vheart[t] - Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, \[Omega],
t]) + (Vheart[t] - Vo)/Cheart) - Paorta[t])/Piecewise[{{Ro, ((Vheart[t] -
Vo)*(1 - (Vheart[t]/25))^2*(Contractility[k, \[Omega], t]) + (Vheart[t] - Vo)/Cheart) -
Paorta[t] > 0}}, x*Ro] - Paorta[t]/Rsystemic),
Vheart[0] == 108, Paorta[0] == 10,  WhenEvent[Paorta'[t]==0,Sow[{t,Paorta[t] }]]}, {Vheart[t], Paorta[t]}, {t, 0, 10}];


which gives the list:

paortaextrm

{{{0.0020065,143.752},{0.570491,98.1404},{0.763708,126.798},{1.56184, 79.9124},{1.77342,111.999},{2.55725,71.1804},{2.77848,105.007},{3.55494,67.0219},{3.781,101.701},{4.55381, 65.0473},{4.78221,100.137},{5.55327,64.1112},{5.7828,99.3966},{6.55301,63.6677},{6.78307,99.046},{7.55289, 63.4577},{7.78321,98.8801},{8.55283,63.3582},{8.78327,98.8015},{9.5528,63.3111},{9.7833,98.7644}}}

as the side product of NDSolve. You can see that this method captures the local extreme points:

Show[Plot[Paorta[t] /. sol, {t, 0, 10}],
ListPlot[paortaextrm, PlotStyle -> Orange]]


The absolute minimum can then be found by comparing these extremes and finding their Min :

list=Flatten[paortaextrm,1]; Min[list[[All,2]]]

63.3111