1
$\begingroup$

Long-time programmer, but new to Mathematica (and for that matter, math). I'm trying to do something that feels pretty basic to me, but that for the life of me, I can't make work:

I want to, having input an array of functions, map them through a higher-order function, resulting in a different array of functions. Something like, very vaguely, this:

D /@ {Sin, Cos, Tan}  (*→ {Cos[x], -Sin[x], Sec[x]^2} *)

(I already understand that I'm using the wrong words to ask this question — but I'm not yet too familiar with Mathematica's terms for things I'd have considered “basic programming things”, as evidenced by the fact that I seem unable to drag a straight answer to this question out of Google and/or Mathematica's documentation. 🤣)


Pursuant to avoiding an X/Y question, here's my current little goal (although doing this in such an over-complicated way is obv. just a learning-Mathematica-programming exercise):

Create a table of the first and second derivatives for each of the trigonometric, inverse-trigonometric, and hyperbolic functions: Sin[x]Cos[x]-Sin[x], so on, so forth, to then copy into a LaTeX document.

I know I can complete the last bit of that with // TableForm, but the first part is stumping me, short of manually typing out {{Sin[x], Cos[x], Tan[x], ...}, {D[Sin[x], x], D[Cos[x], x], D[Tan[x], x], ...}, {...}, {...}}

$\endgroup$
3
  • 1
    $\begingroup$ You want Derivative[] for this: Derivative[1] /@ {Sin, Cos, Tan}. If pure functions still make you uncomfortable: Through[(Derivative[1] /@ {Sin, Cos, Tan})[x]]. $\endgroup$
    – J. M.'s torpor
    Sep 11 '17 at 2:25
  • $\begingroup$ Actually D can do it too. See my answer below. $\endgroup$
    – m_goldberg
    Sep 11 '17 at 4:39
  • 1
    $\begingroup$ For copying to a LaTex document, you can use TeXForm[Table[...]] which will simplify the process a little. Also, if you want to evaluate the functions in the table, one easy way is to define the table as a function: funderivs[x_] = Table[D[...]]. Another way would be to use @J.M.'s pure functions. It would depend on how you want to use them. $\endgroup$ Sep 11 '17 at 4:47
2
$\begingroup$

Perhaps this is what you are looking for.

funcs = {Sin, ArcSin, Cos, ArcCos, Tan, ArcTan};
Table[D[#[x] &, {x, n}] /@ funcs, {n, 0, 2}] // Transpose // TableForm

table

$\endgroup$
1
  • 1
    $\begingroup$ Actually, just the D[ #[x], x] & is precisely what I was looking for — even though I didn't know. Thank you! $\endgroup$ Sep 11 '17 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.