7

I'm interested in using Mathematica's symbolic manipulation to obtain, for a particular function $f$, derivatives of arbitrary order evaluated at zero. Normally I'd use the D command, but $f$ depends on a function $h$ that I can only define implicitly. More precisely, given a constant $a$ and two functions $g$ and $R$, I'd like to calculate $f^{(n)}(0)$ for any given $n$, where

$f(s) := g(a+ h(s)) \, h'(s)$

and $h$ is a function satisfying $h(0) = 0$ and $R(a+h(s))=-s$ for all $s$.

On paper I can of course use implicit differentiation on the last equation and substitute accordingly to obtain the derivatives of $f$ that I'd like in terms of those of $g$ and $R$, but this is eventually quite tedious, so I was looking to automate it. Is there a way to accomplish this in Mathematica?

I've written some pseudocode for a particular example, with the part I'm stuck on denoted by ???. Ideally, I'd like the code defining $h(s)$ to be independent of the particular choice of $a$, $g$ and $R$ so that I don't have to rewrite it if I change the former. Help is greatly appreciated!

(* Example definitions of a, n, g, and R *)
a = 1;
n = 5;
g[s_] := Exp[-s];
R[s_] := Log[s]-s+1;

(* Implicit definition of h[s_] goes here *)
???

(* Define f, take nth derivative, evaluate at 0 *)
f[s_] := g[a + h[s]] h'[s];
D[f[s], {s, n}]/.s->0

Edit: example R was poorly chosen, sorry!

sourisse
  • 259
  • 1
  • 4

1 Answers1

9

Is this what you want?

Clear[Derivative, h];

h[0] = 1;  (* to avoid division by zero with OP's example R *)

Derivative[1][h][s_] := Block[{Derivative},
  h'[\[FormalS]] /. 
    First@Solve[
      D[R[a + h[\[FormalS]]] == - \[FormalS], \[FormalS]], 
      h'[\[FormalS]]] /. \[FormalS] -> s
  ];
Derivative[n_][h][s_] := 
  D[Derivative[n - 1][h][\[FormalS]], \[FormalS]] /. \[FormalS] -> s;

h'[s]
(*  (1 + h[s])/h[s]  *)

h''[s]
(*  (1 + h[s])/h[s]^2 - (1 + h[s])^2/h[s]^3  *)

h'[0]
(*  2  *)

h''[0]
(*  -2  *)

D[f[s], {s, 5}] /. s -> 0
(*  -(38798/E^2)  *)

(Those formal symbols look bad on the site, but they seem the best choice for the code. Or one could use Module to create a unique local symbol for each call.)

Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • This is great, thank you! – sourisse Jun 30 '15 at 01:15
  • @sourisse You're welcome. You might want to read this answer, http://mathematica.stackexchange.com/a/15620, in case you need to undo some mistake and have to undefine the derivative(s). – Michael E2 Jun 30 '15 at 01:52