1
$\begingroup$

I have a function Ca[t] that oscillates like a Sine curve, that I used NDSolve to obtain. I want to calculate the average value of Ca[t] so 1/2(Max+Min) but I have not been able to do this successfully and I don't know what to do.

     Manipulate[

      k1 = 0.5; k2 = 0.2;
      r1 = -k1 Ca[t]^m;
      r2 = -k2 Cb[t]^n;
      xa = (Cao[0] - 
        0.5*(MaxValue[Ca[t], Reals] + MinValue[Ca[t], Reals]))/Cao[0];
      Cao[t_] = 5 + A Sin[ω t];
      sol = NDSolve[{
         Ca'[t] == r1*τ + -Ca[t] + Cao[t],
         Cb'[t] == r2*τ - r1*τ - Cb[t],
         Cc'[t] == -r2*τ - Cc[t],
         Ca[0] == 0,
         Cb[0] == 0,
         Cc[0] == 0},
        {Ca, Cb, Cc}, {t, 0, 100}];

   {{τ, 5, "residence time/min"}, 2, 10, Appearance -> "Labeled"},
   {{ω, 0.6, "frequency"}, 0.2, 2, 0.02, 
           Appearance -> "Labeled"},
   {{A, 2, "amplitude"}, 0.5, 5, 0.05, 
           Appearance -> "Labeled"},
   {{m, 1, "m"}, 0, 2, 1, ControlType -> SetterBar},
   {{n, 1, "n"}, 0, 2, 1, ControlType -> SetterBar}]

This is as much as I can trim my notebook, my latest attempt at calculating the average of Ca[t] inside the expression xa.

$\endgroup$
0
1
$\begingroup$

Not very sophisticated but take a look:

Manipulate[k1 = 0.5; k2 = 0.2;
 r1 = -k1 Ca[t]^m;
 r2 = -k2 Cb[t]^n;
 Cao[t_] = 5 + A Sin[\[Omega] t];
 sol = Quiet@NDSolve[{
                     Ca'[t] == r1*\[Tau] + -Ca[t] + Cao[t], 
                     Cb'[t] == r2*\[Tau] - r1*\[Tau] - Cb[t], 
                     Cc'[t] == -r2*\[Tau] - Cc[t], Ca[0] == 0, Cb[0] == 0, 
                     Cc[0] == 0}, {Ca, Cb, Cc}, {t, 0, 100}];
 Framed@Row@{
  Plot[Evaluate[Ca[t] /. sol], {t, 0, 100}, ImageSize -> 600, Epilog -> {
       PointSize@.01, Point[p = {t /. #2, #1} & @@@Quiet@(
       {FindMinimum[##], FindMaximum[##]} & @@ {Evaluate[Ca[t] /. sol], {t, 60}})]}
      ]
  ,
  "Average \[TildeTilde] ", Dynamic@N[Total[p[[All, 2]]]/2]
 }
 ,
 {{\[Tau], 5, "residence time/min"}, 2, 10, 
  Appearance -> "Labeled"}, {{\[Omega], 0.6, "frequency"}, 0.2, 2, 
  0.02, Appearance -> "Labeled"}, {{A, 2, "amplitude"}, 0.5, 5, 0.05, 
  Appearance -> "Labeled"}, {{m, 1, "m"}, 0, 2, 1, 
  ControlType -> SetterBar}, {{n, 1, "n"}, 0, 2, 1, 
  ControlType -> SetterBar}]

enter image description here

$\endgroup$
5
  • $\begingroup$ Why are you solving for Cb and Cc? ... Ca[] isn't coupled! (r2 and n aren't needed, for a starter) $\endgroup$ – Dr. belisarius Jun 24 '13 at 23:59
  • $\begingroup$ @belisarius Yes, of course. Well I didn't know what user7560 wants a the end, since sol is not scoped He can instatnly use it later. Also, it was not so demanding for my old pc so I left them. $\endgroup$ – Kuba Jun 25 '13 at 5:04
  • $\begingroup$ @belisarius, they are necessary, I just left out the plots. Leaving them in there won't hurt anything for the purposes of this post. $\endgroup$ – baumannr Jun 25 '13 at 14:42
  • $\begingroup$ @Kuba thank you for this, I am going to try this out! $\endgroup$ – baumannr Jun 25 '13 at 14:42
  • $\begingroup$ @user7560 Next time try to post the minimal code snippet that demonstrates the behavior you need to clarify. $\endgroup$ – Dr. belisarius Jun 25 '13 at 14:53

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.