Loops involving derivatives to different orders.

Hi, I’ve had one course in Mathematica, earlier in my math-education, but it was very basic.

Now, I’m trying to find a way to compute a list where I get the derivative up to, and including, the derivative of order n, for each polynomial in another list that I have defined.

Let me illustrate:

For[k = 1, k <= Length[specifiednus], k++,Table[D[Outpt[[k]],{t,i}],{i,0,specifiednus[[k]]}]]

This does not work.

This does work:

Table[D[Outpt[[1]],{t,i}],{i,0,specifiednus[[1]]}]

Output is a list of polynomials. “specifiednus” specifies which order of the derivative you want. Let’s say specifiednus[[1]] = 2. That means that I want the original polynomial, and it’s first two derivatives.

So, I want all of the derivatives up to the degree specified by the list “specifiednus”, for each polynomial, and the original polynomials, in one list.

Any suggestions?

Best,

Ben

Hi Benjamin,

Something like this?

ClearAll@x;
polys = Array[x^# &, 4]
(* {x, x^2, x^3, x^4} *)

orders = {0, 1, 1, 2};

derivs = MapThread[D[#1, {x, #2}] &, {polys, orders}]
(* {x, 2 x, 3 x^2, 12 x^2} *)

Not sure what you mean by “and the original polynomials, in one list”? Maybe

polysAndDerivs = MapThread[{#1, D[#1, {x, #2}]} &, {polys, orders}]
(* {{x, x}, {x^2, 2 x}, {x^3, 3 x^2}, {x^4, 12 x^2}} *)

Edit

Oops, I missed this bit “the derivative up to, and including, the derivative of order n”

derivList[f_, n_] := Table[D[f, {x, i}], {i, 0, n}];
MapThread[derivList[#1, #2] &, {polys, orders}]
(* {{x}, {x^2, 2 x}, {x^3, 3 x^2}, {x^4, 4 x^3, 12 x^2}} *)

Like this perhaps?

outpt = {p1[x], p2[x], p3[x], p4[x]}
specifiednus = RandomInteger[{1, 5}, 4]
dat = Transpose[{specifiednus, outpt}]
Function[{j, u}, Table[Derivative[i][u], {i, 1, j}]] @@@ dat

Edit:

This is better

outpt = {p1[x], Sin[x], p3[x], x^n}
specifiednus = RandomInteger[{1, 8}, 4]
dat = Transpose[{specifiednus, outpt}]
Function[{j, u}, Table[D[u, {x, i}], {i, 1, j}]] @@@ dat;
% // ColumnForm

Thanks guys, it seems like this

Table[D[Outpt[[k]],{t,i}],{i,0,specifiednus[[k]]}],{k,1,Length[Outpt]}];
upcat = Flatten[cat];

Did the trick.

I got the tips from some other forum, I believe stack-exchange or something similar.

Or

Inner[Table[D[#1, {x, i}], {i, #2}] &, outpt, specifiednus, List]