bdavis8594
(Brandon Davis)
October 15, 2016, 10:14pm
1
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
benshimo
(Yehuda Ben-Shimol)
October 15, 2016, 11:43pm
2
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