TransWikia.com

Help to Write a Function for Multiple Derivatives

Mathematica Asked by rainman on March 30, 2021

I am new to Mathematica and still struggling to learn basic things. In this spirit, I am trying to compute the following expression:

$$C_n = left[ frac{partial^n W(J)}{partial J^n}right]_{J=0},$$
where $W(J) = ln Z(J) = ln left[sum_{n=0}^{infty}frac{1}{n!} J^n G_nright]$, and $G_n$s are different non-zero constants.

How can I write a function for computing $C_n$ where I would input the value of $n$ and get the corresponding expressions? For instance, $C_1 = G_1$, $C_2 = G_2-G_1^2$, etc. We assume that $G_0=1$.

My current approach is very elementary. It is given below.

Z[J_] = g0 + g1 J + g2/2 J^2 + g3/3! J^3 + g4/4! J^4 + g5/5! J^5 + g6/6! J^6
g0 = 1
W[J_] = Log[Z[J]]
C1[J_] = D[W[J], {J, 1}]
C1[0]

Could you please help me to improve it? A sample code would help me a lot.

One Answer

Clear["Global`*"]

Z[J_] = g0 + g1 J + g2/2 J^2 + g3/3! J^3 + g4/4! J^4 + g5/5! J^5 + g6/6! J^6;

W[J_] = Log[Z[J]];

The nth derivative of W evaluated at zero is just

c[n_Integer?NonNegative] := c[n] = Derivative[n][W][0]

The first several are

seq1 = c /@ Range[0, 5] // Simplify

(* {Log[g0], g1/g0, (-g1^2 + g0 g2)/g0^2, (
 2 g1^3 - 3 g0 g1 g2 + g0^2 g3)/g0^3, (-6 g1^4 + 12 g0 g1^2 g2 - 
  4 g0^2 g1 g3 + 
  g0^2 (-3 g2^2 + g0 g4))/g0^4, (1/(g0^5))(24 g1^5 - 60 g0 g1^3 g2 + 
   20 g0^2 g1^2 g3 - 5 g0^2 g1 (-6 g2^2 + g0 g4) + g0^3 (-10 g2 g3 + g0 g5))} *)

Alteratively,

c2[n_Integer?NonNegative] := c2[n] = n!*SeriesCoefficient[W[J], {J, 0, n}]

seq2 = c2 /@ Range[0, 5] // Simplify

(* {Log[g0], g1/g0, (-g1^2 + g0 g2)/g0^2, (
 2 g1^3 - 3 g0 g1 g2 + g0^2 g3)/g0^3, (-6 g1^4 + 12 g0 g1^2 g2 - 
  4 g0^2 g1 g3 + 
  g0^2 (-3 g2^2 + g0 g4))/g0^4, (1/(g0^5))(24 g1^5 - 60 g0 g1^3 g2 + 
   20 g0^2 g1^2 g3 - 5 g0^2 g1 (-6 g2^2 + g0 g4) + g0^3 (-10 g2 g3 + g0 g5))} *)

seq1 === seq2

(* True *)

Correct answer by Bob Hanlon on March 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP