# Averaging an oscillating function

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[\[Omega] t];
sol = 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}];

{{\[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}]


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

-

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}]


-
Why are you solving for Cb and Cc? ... Ca[] isn't coupled! (r2 and n aren't needed, for a starter) –  belisarius Jun 24 '13 at 23:59
@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. –  Kuba Jun 25 '13 at 5:04
@belisarius, they are necessary, I just left out the plots. Leaving them in there won't hurt anything for the purposes of this post. –  user7560 Jun 25 '13 at 14:42
@Kuba thank you for this, I am going to try this out! –  user7560 Jun 25 '13 at 14:42
@user7560 Next time try to post the minimal code snippet that demonstrates the behavior you need to clarify. –  belisarius Jun 25 '13 at 14:53