Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Can I integrate something that is specified by the values in an array

Posted 5 years ago

Dear All, I would like to integrate something that is the values in an array (y) as a function of a variable that is given by the values in another array x. Graphically I would just plot y against x and find the area under the graph. Is there a more sophisticated way of doing it using Mathematica? All help welcome. Thanks. John Hey

POSTED BY: John Hey
4 Replies

Dear Rohit,

Thanks. All is clear now.

John

POSTED BY: John Hey
Posted 5 years ago

Hi John,

Expanding on Neil's answer:

For equally spaced points

delta = Pi/50;
data = Table[N@Sin[x], {x, 0, Pi, delta}];
Total[delta*data]
(* 1.99934 *)

For unequally spaced points you can use Interpolation

xVals = Table[x + RandomReal[{-delta, delta}/2], {x, 0, Pi, delta}];
yVals = Sin[xVals];
points = Transpose[{xVals, yVals}];

iFun = Interpolation[points]
Integrate[iFun[x], {x, Min@xVals, Max@xVals}]
(* 1.9995 *)
POSTED BY: Rohit Namjoshi

Dear Neil, You are wonderful. Many thanks. John

POSTED BY: John Hey

John,

If the values are equally spaced use Total[] to integrate the curve and multiply by the time spacing. If not, you can do the calculation point by point

Regards

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard