1
$\begingroup$

I would like to perform a numerical integration between the x-axis and some values.

1st value is x and the second y. My code looks like this:

d={{0., -1.11}, {0.01, 2.22}, {0.02, 0.}, {0.03, -2.22}, {0.04, 2.22}, {0.05, -1.11}, {0.06, -1.11},{0.07, 2.22}, {0.08, 0.}, {0.09, 0.}, {0.1, -1.11}}
dt=0.01

de = Sum[{ (d[[nn + 1, 2]] + d[[nn, 2]])*dt}, {nn, Length[d] - 1}]

How do I integrate only positive values?

$\endgroup$
2
  • $\begingroup$ Have you already seen Max[] or Clip[]? $\endgroup$
    – J. M.'s torpor
    Jan 26 at 21:21
  • $\begingroup$ Hi, just wondering, is it possible that there is a $\frac{1}{2}$ missing? $\endgroup$
    – NG98
    Jan 26 at 21:41
1
$\begingroup$

maybe you can define the positive part of your function. $$f^+:=\max\{f,0\},$$ and integrate this new function.

de = Sum[
       {(Max[d[[nn + 1, 2]], 0] + 
           Max[d[[nn, 2]], 0])*dt}, 
       {nn, Length[d] - 1}]
$\endgroup$
0

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.