Message Boards Message Boards

0
|
4983 Views
|
1 Reply
|
4 Total Likes
View groups...
Share
Share this post:

Integrate repeatedly like the Derivative command?

Posted 8 years ago

I am trying to compute multiple integrals for a function. For example we will start with code for multiple derivatives..

Clear[f,x];
f[x_] = Sin[x];
TableForm[Table[D[f[x], {x, n}], {n, 1, 5}]]

would produce

{
 {Cos[x]},
 {-Sin[x]},
 {-Cos[x]},
 {Sin[x]},
 {Cos[x]}
}

But what about multiple integrals? Using f[x] = x as an example.

I know this is how to integrate, but what about

    Clear[f, x];
    f[x_] = x;
   antideriv = Integrate[f[x],x];
   antideriv
POSTED BY: Brandon Davis

It is not efficient to compute derivatives n times if you already computed derivative n-1 NestList keeps track of the result, so with a little modification this can do the computation you need for both derivative and integration

Clear[f, x];
f[x_] = Sin[x];
TableForm[NestList[D[#, x] &, f[x], 5]]
TableForm[NestList[Integrate[#, x] &, f[x], 5]]

If you do not want the first element in the list (which is f[x], than just use Rest to drop the first element of the list, that is

Clear[f, x];
f[x_] = Sin[x];
TableForm[Rest@NestList[D[#, x] &, f[x], 5]]
TableForm[Rest@NestList[Integrate[#, x] &, f[x], 5]]

best yehuda

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

Group Abstract Group Abstract