4
$\begingroup$

I have next code

a = 1;
T = 25;
Subscript[I, 1] = If[t < T, a*t, 2*a*T - a*t];
Plot[Subscript[I, 1], {t, 0, 2 T}, AxesLabel -> {t, I1}]

enter image description here

I need to find average current on some interval, for this I do next

t1 = 1;
t2 = 5;
f = 1;
b = Table[If[i <= T, a*i, 2*a*T - a*t], {i, t1, t2, f}]
Subscript[I1, average] = Total[b]/Length[b]

It calculates average current correctly only to 25 value, after that all values are not correct. This error occurs because i don't include 25 value in false condition. How can I fix it? And How can I to get result in List form?

$\endgroup$

2 Answers 2

5
$\begingroup$
Plot[TriangleWave[x/100], {x, 0, 50}]

Integrate[TriangleWave[x/100], {x, 0, 50}]/50
$\endgroup$
1
  • 3
    $\begingroup$ You need to divide by the base width of 50 to get there average of 1/2 $\endgroup$
    – Bob Hanlon
    Nov 29, 2016 at 1:54
2
$\begingroup$

Using your code (in case you need to use Table):

a = 1;
T = 25;
i1[t_, T_, a_] = Piecewise[{{a*t, t < T}}, 2*a*T - a*t];
t1 = 1;
t2 = 5;
i1avg = {(Mean@Table[i1[t, T, a], {t, t1, Min[t2, T]}] Max[0, (Min[t2, T] - t1)] + 
          Mean@Table[i1[t, T, a], {t, Max[t1, T], t2}] Max[0, (t2 - Max[t1, T])])
         /(t2 - t1)
        }
$\endgroup$
2
  • 1
    $\begingroup$ does this not give the same inaccurate result as the OP method? If you want to sum discrete values you should use the trapezoidal rule. $\endgroup$
    – george2079
    Nov 29, 2016 at 12:56
  • $\begingroup$ @george2079 Good catch! Didn't look at the underlying. Fixed the answer. $\endgroup$
    – Stitch
    Nov 29, 2016 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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