1
$\begingroup$

I have a two variable function z[x,y] = f[x,y] + g[x,y], such that I know the functional form of f[x,y] but not of g[x,y]. I have to do some symbolic calculations with the function z[x,y], but I would like to keep only the first order in g[x,y] (treating g as small). So, for example, I would like Mathematica to approximate (z[x,y])^3 = (f[x,y] + g[x,y])^3 = f[x,y]^3 + 3*f[x,y]^2*g[x,y], or (D[z[x,y], x])^2 = (D[f[x,y], x])^2 + 2*D[f[x,y], x]*D[g[x,y], x]. Is there a way to do it? I have tried the most naive way, namely to use Series['exp'[z],{g, 0, 1}], treating g[x,y] as a parameter rather than a function, but (as expected) it doesn't work. Do you know a way to do it?

Thank you very much in advance for anyone who will reply!

$\endgroup$

2 Answers 2

2
$\begingroup$

Here a simple approach which assumes g and its derivatives(!) to be small:

z[x,y]:= f[x,y]+eps g[x,y]

Normal[Series[(f[x, y] + eps g[x, y])^3, {eps, 0, 1}]] /. eps -> 1
(*f[x, y]^3 + 3 f[x, y]^2 g[x, y]*)

Normal[Series[D[z[x, y] ^2, x], {eps, 0, 1}]] /. eps -> 1
(*2 f[x, y] Derivative[1, 0][f][x, y] + 2 g[x, y] Derivative[1, 0][f][x, y] + 2 f[x, y] Derivative[1, 0][g][x, y]*)
$\endgroup$
2
  • $\begingroup$ Thank you! This is exactly what I was looking for! $\endgroup$
    – PPIP
    Commented Apr 16, 2021 at 7:53
  • $\begingroup$ @PPIP You're welcome! $\endgroup$ Commented Apr 16, 2021 at 8:27
2
$\begingroup$

You can use O to drop higher-order terms:

Clear[f, g, z]
z[x_, y_] := f[x, y] + g[x, y]

z[x, y]^3 + O[g[x, y]]^2

series expression still containing O

If you want an expression without the O, use Normal:

z[x, y]^3 + O[g[x, y]]^2 // Normal

(* Out: f[x, y]^3 + 3 f[x, y]^2 g[x, y] *)

This works for the derivative as well:

D[z[x, y], x]^2 + O[g[x, y]]^2 // Normal // Expand

(* Out:
   Derivative[1, 0][f][x, y]^2 + 
     2*Derivative[1, 0][f][x, y] * Derivative[1, 0][g][x, y] + 
       Derivative[1, 0][g][x, y]^2
*)
$\endgroup$
2
  • $\begingroup$ Nice idea ! For the derivative I would expect a result without the last part Derivative[1, 0][g][x, y]^2 $\endgroup$ Commented Apr 16, 2021 at 7:32
  • $\begingroup$ Thank you! I was looking for something that automatically neglects also the last term in the derivative, as Ulrich said, but your insight was very useful as well! $\endgroup$
    – PPIP
    Commented Apr 16, 2021 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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