2
$\begingroup$

I would like create a function that takes functions as input and includes different partial derivatives of the input functions, for simplicity's sake say:

$\qquad m(f(x,y),g(x,y))=f_{xxx}(x,y)+g_{xyy}(x,y)$

I've tried looking but couldn't find a solution to this type of problem here, how would I create the function $m$?

Clarifcation on input functions: I want it to work for any function I've defined myself, like func[x_, y_] := 1 + x y + Sin[x + y] (guess that's the syntax still new to mathematica).

$\endgroup$
3
  • 2
    $\begingroup$ Does this work? m[f_, g_] := Fold[D[#1, #2] &, f[x, y], {x, x, x}] + Fold[D[#1, #2] &, g[x, y], {x, y, y}], or perhaps this m[f_, g_] := Derivative[1, 2][g][x, y] + Derivative[3, 0][f][x, y] ? $\endgroup$ Commented Nov 29, 2020 at 16:45
  • 1
    $\begingroup$ When you write " take functions" do you mean function symbols such as Sin or 'f, expressions such as 1 + x y + Sin[x + y], or pure functions such as (1 + #1 #2 +Sin[#1 #2])&`? $\endgroup$ Commented Nov 29, 2020 at 16:46
  • $\begingroup$ @m_goldberg I'm not sure on the difference but I want to be able to give it any arbitrary function I can define myself, I guess that would be expressions like 1 + x y + Sin[x + y] $\endgroup$ Commented Nov 29, 2020 at 17:00

1 Answer 1

1
$\begingroup$

Following up on the comments after the clarification of OP. Depending on what exactly one wants as input and output of the desired function m the approach differs slightly:

m1[f_,g_,{x_,y_}]:=Derivative[1,2][g][x,y]+Derivative[3,0][f][x,y] m2[f_,g_]:=Derivative[1,2][g][x,y]+Derivative[3,0][f][x,y] m3[f_,g_]:=Derivative[1,2][g]+Derivative[3,0][f] 

m1 returns the sum of derivatives evaluated at the variables x and y, m2 returns the sum of derivatives evaluated at the global symbols x and y (might be set to a value) and m3 returns a pure function for the sum of derivatives:

y=a; f[x_,y_]:=1+x y+Sin[x+y] g=1+#1 #2+Sin[#1 #2]&; m1[f,g,{x1,y1}] m2[f,g] m3[f,g] 

returns

result

where f is a function with named arguments set using SetDelay, g is a pure function with unnamed arguments, and y is a global variable set to the (here undefined) symbol a. The definitions for m1, m2 and m3 work only with functions, not with expressions. For expressions one would need something along the lines

ClearAll[x, y] m4[f_, g_, {x, y}] := D[f, {x, 3}] + D[D[g, x], {y, 2}] m4[1 + x y + Sin[x + y], 1 + x y + Sin[x + y], {x, y}] 

returning -2 Cos[x + y] as expected. In all cases one has to be car full with the function arguments/global symbols: e.g. m4 will not work if x or y are set to non-symbol objects (like e.g. y=42).

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.