0
$\begingroup$

My script is currently:

 NDSolve[{cd'[t] == -k1 cd[t], cd[0] == c0, 
     cno'[t] == k1 cd[t] eNO - k2 o cno[t]^2, cno[0] == 0}, {cd, 
     cno}, {t, 0, 2400}]

Plot[Evaluate[cno[t] /. %], {t, 0, 100}, PlotRange -> {0, 10 10^-6}]

this gives me my plot and what I want to get the actual value for the max of this curve?

I am not sure what code to put in after FindMaximum to get it.

$\endgroup$
  • 2
    $\begingroup$ Please add some more details to your code so that there is a minimum working example - right now if I paste the code you shared into Mathematica I just get a load of errors because a lot of things are undefined :) You may have success trying FindMaximum[Evaluate[cno[t] /. %], {t, 1}], or consider looking at NMaximize. $\endgroup$ – Carl Lange Nov 26 '18 at 15:40
1
$\begingroup$

You could include a WhenEvent in your ODE to capture local maxima. First, some random values for your constants:

k1 = .3;
k2 = .7;
o = 10;
c0 = 1;
eNO = 5;

Then, use NDSolveValue with WhenEvent:

{sol, {max}} = Reap @ NDSolveValue[
    {
    cd'[t] == -k1 cd[t], cd[0] == c0, cno'[t] == k1 cd[t] eNO - k2 o cno[t]^2, cno[0]==0,
    WhenEvent[cno'[t] == 0, Sow @ cno[t]]
    },
    {cd, cno},
    {t, 0, 2400}
];

There is only 1 maximum:

max

{0.415782}

Visualization:

Plot[sol[[2]][t], {t, 0, 10}, GridLines -> {None, max}]

enter image description here

|improve this answer|||||
$\endgroup$
0
$\begingroup$
eqns = {cd'[t] == -k1 cd[t], cd[0] == c0, 
   cno'[t] == k1 cd[t] eNO - k2 o cno[t]^2, cno[0] == 0};

The equations can be solved using DSolve

sol = DSolve[eqns, {cd, cno}, t][[1]] // Quiet

(* {cd -> Function[{t}, c0 E^(-k1 t)], 
 cno -> Function[{t}, (-Sqrt[c0] Sqrt[E^(-k1 t)] Sqrt[eNO] Sqrt[k1]
        BesselI[1, (2 Sqrt[c0] Sqrt[E^(-k1 t)] Sqrt[eNO] Sqrt[k2] Sqrt[o])/
        Sqrt[k1]] BesselK[1, (2 Sqrt[c0] Sqrt[eNO] Sqrt[k2] Sqrt[o])/Sqrt[
        k1]] + Sqrt[c0] Sqrt[E^(-k1 t)] Sqrt[eNO] Sqrt[k1]
        BesselI[1, (2 Sqrt[c0] Sqrt[eNO] Sqrt[k2] Sqrt[o])/Sqrt[k1]] BesselK[
        1, (2 Sqrt[c0] Sqrt[E^(-k1 t)] Sqrt[eNO] Sqrt[k2] Sqrt[o])/Sqrt[
        k1]])/(Sqrt[k2] Sqrt[
      o] (BesselI[1, (2 Sqrt[c0] Sqrt[eNO] Sqrt[k2] Sqrt[o])/Sqrt[
          k1]] BesselK[0, (
          2 Sqrt[c0] Sqrt[E^(-k1 t)] Sqrt[eNO] Sqrt[k2] Sqrt[o])/Sqrt[k1]] + 
        BesselI[0, (2 Sqrt[c0] Sqrt[E^(-k1 t)] Sqrt[eNO] Sqrt[k2] Sqrt[o])/
          Sqrt[k1]] BesselK[1, (2 Sqrt[c0] Sqrt[eNO] Sqrt[k2] Sqrt[o])/Sqrt[
          k1]]))]} *)

Verifying that sol satisfies the equations

eqns /. sol // FullSimplify

(* {True, True, True, True} *)

Using the constants used by Carl Woll

k1 = 3/10;
k2 = 7/10;
o = 10;
c0 = 1;
eNO = 5;

NMaximize[cno[t] /. sol, t]

(* {0.415782, {t -> 0.715805}} *)

Or

FindMaximum[cno[t] /. sol, t]

(* {0.415782, {t -> 0.715805}} *)
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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