Using the TableForm command, I want to find the derivatives up to the fourth order of the function $f(x)=\cos{x^2}/x$ and give the results in Matrix form.
3 Answers
Many ways to do this. One is
f[x_] := Cos[x^2]/x
data = {TraditionalForm[HoldForm@D[f[x], {x, #}]],
TraditionalForm[D[f[x], {x, #}]]} & /@ Range[4];
PrependTo[data, {Row[{TraditionalForm[HoldForm@f[x]], "=",
TraditionalForm[f[x]]}], "output"}]
Grid[data, Frame -> All]
You did not say if this is for display only or not. If you want to use the data, then you can remove the Grid part. If it is for display only, you can also use TeXForm and MaTeX to make nice Latex table with caption title and figure numbers to include in your latex document so you can reference the table from other places in the document.
Clear["Global`*"]
f[x_] := Cos[x^2]/x
Using MatrixForm
(note that the "forms" are not included in the scope of the definition of mat
)
(mat = NestList[{#[[1]] + 1, Simplify[D[#[[2]], x]]} &, {0, f[x]},
4]) // TraditionalForm // MatrixForm
Using TableForm
TableForm[mat,
TableHeadings -> {None, {n,
Superscript[f, "(n)"][x]}}] // TraditionalForm
Using FoldList
while calculating derivs
in addition to mostly borrowed formatting techniques:
f[x_] := Cos[x^2]/x
n = 5;
derivs = FoldList[D[#, x] &, f[x], Range[n]];
ops = TraditionalForm@HoldForm[Derivative[#][f][x]] & /@ Range[0, n];
data = Transpose@{TraditionalForm /@ Range[0, n], ops,
TraditionalForm /@ derivs};
Grid[#, Frame -> All
, Alignment -> {Center, Center}
, Spacings -> {1, 2}
, ItemSize -> {{Scaled[.1], Scaled[.1], Scaled[0.8]}}
] &@
PrependTo[data
, TraditionalForm /@ {"n", Superscript[f, "(n)"][x], "Output"}
]
TableForm[Table[D[Cos[x]^2/x,{x,n}],{n,1,4}]]
Why do you need this in any "Form" Often using "Form" causes more trouble, not less, but I realize that many feel they MUST desktop publish their result. Exactly what did you do and Exactly what is wrong with it and Exactly what do you really have to have? $\endgroup$