1
$\begingroup$

I have the following oscillatory function of time (it looks too lengthy!)

    myfun[t_] = 
  1/Log[2] (-((-E^(-0.001` t) (0.001` Cos[0.09999499987499376` t] - 
              0.09999499987499376` Sin[0.09999499987499376` t]) + 
           0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[0.09999499987499376` t]))/(1 -
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[
                0.09999499987499376` t]))^2) + ((1 - 
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t])) (E^(-0.002` t) (0.001` Cos[
                 0.09999499987499376` t] - 
               0.09999499987499376` Sin[0.09999499987499376` t]) (Cos[
                0.09999499987499376` t] + 
               0.010000500037503125` Sin[0.09999499987499376` t]) - 
            0.001` E^(-0.002` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t])^2) + (-E^(-0.001` t) \
(0.001` Cos[0.09999499987499376` t] - 
               0.09999499987499376` Sin[0.09999499987499376` t]) + 
            0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[0.09999499987499376` t])) (1/
            2 + 
            1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t])^2))/(2 (1 - 
           E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[0.09999499987499376` t]))^(
         3/2) \[Sqrt]((1 - 
              E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])) (1/2 + 
              1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])^2))) - (3 (-E^(-0.001` t) \
(0.001` Cos[0.09999499987499376` t] - 
              0.09999499987499376` Sin[0.09999499987499376` t]) + 
           0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[
                0.09999499987499376` t])) \[Sqrt]((1 - 
              E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])) (1/2 + 
              1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])^2)))/(2 (1 - 
           E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[0.09999499987499376` t]))^(
         5/2))) + 
   1/Log[2] Log[
      1/(1 - E^(-0.001` t) (Cos[0.09999499987499376` t] + 
           0.010000500037503125` Sin[
             0.09999499987499376` t])) + (\[Sqrt]((1 - 
              E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])) (1/2 + 
              1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])^2)))/(1 - 
          E^(-0.001` t) (Cos[0.09999499987499376` t] + 
             0.010000500037503125` Sin[0.09999499987499376` t]))^(
        3/2)] (-((-E^(-0.001` t) (0.001` Cos[
                 0.09999499987499376` t] - 
               0.09999499987499376` Sin[0.09999499987499376` t]) + 
            0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t]))/(1 - 
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t]))^2) + ((1 - 
             E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                0.010000500037503125` Sin[

                  0.09999499987499376` t])) (E^(-0.002` t) (0.001` \
Cos[0.09999499987499376` t] - 
                0.09999499987499376` Sin[
                  0.09999499987499376` t]) (Cos[
                 0.09999499987499376` t] + 
                0.010000500037503125` Sin[0.09999499987499376` t]) - 
             0.001` E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                0.010000500037503125` Sin[
                  0.09999499987499376` t])^2) + (-E^(-0.001` t) \
(0.001` Cos[0.09999499987499376` t] - 
                0.09999499987499376` Sin[0.09999499987499376` t]) + 
             0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                0.010000500037503125` Sin[
                  0.09999499987499376` t])) (1/2 + 
             1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                0.010000500037503125` Sin[
                  0.09999499987499376` t])^2))/(2 (1 - 
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[0.09999499987499376` t]))^(
          3/2) \[Sqrt]((1 - 
               E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                  0.010000500037503125` Sin[
                    0.09999499987499376` t])) (1/2 + 
               1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 

                  0.010000500037503125` Sin[
                    0.09999499987499376` t])^2))) - (3 (-E^(-0.001` \
t) (0.001` Cos[0.09999499987499376` t] - 
               0.09999499987499376` Sin[0.09999499987499376` t]) + 
            0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t])) \[Sqrt]((1 - 
               E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                  0.010000500037503125` Sin[
                    0.09999499987499376` t])) (1/2 + 
               1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                  0.010000500037503125` Sin[
                    0.09999499987499376` t])^2)))/(2 (1 - 
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[0.09999499987499376` t]))^(
          5/2))) + 
   1/Log[2] (-((-E^(-0.001` t) (0.001` Cos[0.09999499987499376` t] - 
              0.09999499987499376` Sin[0.09999499987499376` t]) + 
           0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[0.09999499987499376` t]))/(1 -
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[
                0.09999499987499376` t]))^2) - ((1 - 
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t])) (E^(-0.002` t) (0.001` Cos[
                 0.09999499987499376` t] - 
               0.09999499987499376` Sin[0.09999499987499376` t]) (Cos[
                0.09999499987499376` t] + 
               0.010000500037503125` Sin[0.09999499987499376` t]) - 
            0.001` E^(-0.002` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t])^2) + (-E^(-0.001` t) \
(0.001` Cos[0.09999499987499376` t] - 
               0.09999499987499376` Sin[0.09999499987499376` t]) + 
            0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[0.09999499987499376` t])) (1/
            2 + 1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t])^2))/(2 (1 - 
           E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[0.09999499987499376` t]))^(
         3/2) \[Sqrt]((1 - 
              E^(-0.001` t) (Cos[0.09999499987499376` t] + 

                 0.010000500037503125` Sin[
                   0.09999499987499376` t])) (1/2 + 
              1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])^2))) + (3 (-E^(-0.001` t) \
(0.001` Cos[0.09999499987499376` t] - 
              0.09999499987499376` Sin[0.09999499987499376` t]) + 
           0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[
                0.09999499987499376` t])) \[Sqrt]((1 - 
              E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])) (1/2 + 
              1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])^2)))/(2 (1 - 
           E^(-0.001` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[0.09999499987499376` t]))^(
         5/2))) + 
   1/Log[2] Log[
      1/(1 - E^(-0.001` t) (Cos[0.09999499987499376` t] + 
           0.010000500037503125` Sin[
             0.09999499987499376` t])) - (\[Sqrt]((1 - 
              E^(-0.001` t) (Cos[0.09999499987499376` t] + 

                 0.010000500037503125` Sin[
                   0.09999499987499376` t])) (1/2 + 
              1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                 0.010000500037503125` Sin[
                   0.09999499987499376` t])^2)))/(1 - 
          E^(-0.001` t) (Cos[0.09999499987499376` t] + 
             0.010000500037503125` Sin[0.09999499987499376` t]))^(
        3/2)] (-((-E^(-0.001` t) (0.001` Cos[
                 0.09999499987499376` t] - 
               0.09999499987499376` Sin[0.09999499987499376` t]) + 
            0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t]))/(1 - 
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t]))^2) - ((1 - 
             E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                0.010000500037503125` Sin[
                  0.09999499987499376` t])) (E^(-0.002` t) (0.001` \
Cos[0.09999499987499376` t] - 
                0.09999499987499376` Sin[
                  0.09999499987499376` t]) (Cos[
                 0.09999499987499376` t] + 
                0.010000500037503125` Sin[0.09999499987499376` t]) - 
             0.001` E^(-0.002` t) (Cos[0.09999499987499376` t] + 

                0.010000500037503125` Sin[
                  0.09999499987499376` t])^2) + (-E^(-0.001` t) \
(0.001` Cos[0.09999499987499376` t] - 
                0.09999499987499376` Sin[0.09999499987499376` t]) + 
             0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                0.010000500037503125` Sin[
                  0.09999499987499376` t])) (1/2 + 
             1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                0.010000500037503125` Sin[
                  0.09999499987499376` t])^2))/(2 (1 - 
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[0.09999499987499376` t]))^(
          3/2) \[Sqrt]((1 - 
               E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                  0.010000500037503125` Sin[
                    0.09999499987499376` t])) (1/2 + 
               1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                  0.010000500037503125` Sin[
                    0.09999499987499376` t])^2))) + (3 (-E^(-0.001` \
t) (0.001` Cos[0.09999499987499376` t] - 
               0.09999499987499376` Sin[0.09999499987499376` t]) + 
            0.001` E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[
                 0.09999499987499376` t])) \[Sqrt]((1 - 
               E^(-0.001` t) (Cos[0.09999499987499376` t] + 
                  0.010000500037503125` Sin[
                    0.09999499987499376` t])) (1/2 + 
               1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
                  0.010000500037503125` Sin[
                    0.09999499987499376` t])^2)))/(2 (1 - 
            E^(-0.001` t) (Cos[0.09999499987499376` t] + 
               0.010000500037503125` Sin[0.09999499987499376` t]))^(
          5/2))) + (Log[
       1/2 - 1/2 Sqrt[
         1/2 + 1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
             0.010000500037503125` Sin[
               0.09999499987499376` t])^2]] (E^(-0.002` t) (0.001` \
Cos[0.09999499987499376` t] - 
           0.09999499987499376` Sin[0.09999499987499376` t]) (Cos[
            0.09999499987499376` t] + 
           0.010000500037503125` Sin[0.09999499987499376` t]) - 
        0.001` E^(-0.002` t) (Cos[0.09999499987499376` t] + 
           0.010000500037503125` Sin[
             0.09999499987499376` t])^2))/(4 Log[2] Sqrt[
      1/2 + 1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
          0.010000500037503125` Sin[
            0.09999499987499376` t])^2]) - (Log[
       1/2 (1 + Sqrt[
          1/2 + 1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
              0.010000500037503125` Sin[
                0.09999499987499376` t])^2])] (E^(-0.002` t) (0.001` \
Cos[0.09999499987499376` t] - 
           0.09999499987499376` Sin[0.09999499987499376` t]) (Cos[
            0.09999499987499376` t] + 
           0.010000500037503125` Sin[0.09999499987499376` t]) - 
        0.001` E^(-0.002` t) (Cos[0.09999499987499376` t] + 
           0.010000500037503125` Sin[
             0.09999499987499376` t])^2))/(4 Log[2] Sqrt[
      1/2 + 1/2 E^(-0.002` t) (Cos[0.09999499987499376` t] + 
          0.010000500037503125` Sin[0.09999499987499376` t])^2]);

This function gives an oscillating curve. I want to integrate only over those time intervals for which curve is positive. How can this be achieved using Mathematica?

Edit: I stand corrected. I want to integrate over the time intervals for which myfun is positive (not its slope).

$\endgroup$
  • $\begingroup$ "over the time intervals for which myfun is positive" - then just use Clip[] or Max[] $\endgroup$ – J. M. will be back soon Apr 1 at 9:22
  • $\begingroup$ Could you kindly explain it as an answer? $\endgroup$ – H. Kenan Apr 1 at 9:23
4
$\begingroup$

As J.M. says, clip the function to positive values:

Plot[Clip[myfun[t], {0, ∞}], {t, 0, 200}]

Then you can integrate it using Integrate or NIntegrate:

NIntegrate[Clip[myfun[t], {0, ∞}], {t, 0, 200}, Method -> "LocalAdaptive"]

266.413

Alternatively, you can notice that the positive intervals are $[T,2T]$, $[3T,4T]$, $[5T,6T]$ etc. with $T=π/0.09999499987499376$. Thus the integral over the $i^{\text{th}}$ positive interval is

posint[i_Integer /; i >= 1] := 
  With[{T = π/0.09999499987499376}, 
    NIntegrate[myfun[t], {t, (2 i - 1) T, (2 i) T}]]

The above result is confirmed with

Sum[posint[i], {i, 3}]

266.413

$\endgroup$
  • $\begingroup$ Thanks, @Roman. I want the integral as a curve/plot (indefinite integral). Can it be done? $\endgroup$ – H. Kenan Apr 2 at 5:27
  • $\begingroup$ Your formula looks too complex for an analytic integration. $\endgroup$ – Roman Apr 2 at 9:09

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.