0
$\begingroup$

I have a function with four variable, let's suppose it as f(t,x,y,z). I want to define a For loop in which in each iteration, differentiation operator acts on the f(t,x,y,z) with respect each variable. For instance, in the first round, differentiation should be done with respect t, in the second round differentiation should be done with respect x, in the third round differentiation should be done with respect y and in the last round differentiation should be done with respect z. I don't know how I should make this program in Mathematica.

Can you help me?

Best Regards

Hadi

$\endgroup$
0
$\begingroup$

Thanks dears. I have found the solution. You can see the solution in the below.

ClearAll["Global`*"]
f[x_, y_, z_] := Sin[x y z]/(x^2 + y^2 + z^2);
dv = {x, y, z};
For[i = 1, i <= 3, i++,
Print[D[f[x, y, z], dv[[i]]]] ]

Then after running the code we have

(y z Cos[x y z])/(x^2+y^2+z^2)-(2 x Sin[x y z])/(x^2+y^2+z^2)^2

(x z Cos[x y z])/(x^2+y^2+z^2)-(2 y Sin[x y z])/(x^2+y^2+z^2)^2

(x y Cos[x y z])/(x^2+y^2+z^2)-(2 z Sin[x y z])/(x^2+y^2+z^2)^2

Thank you everybody.

$\endgroup$
  • $\begingroup$ I'm glad you were able to find a solution yourself! You would likely benefit from using something like Table rather than For : Table[ D[f[x, y, z], dv[[i]] ], {i,1,3} ]. This will return a list of all three outputs, which you can further manipulate. $\endgroup$ – jjc385 Mar 29 '17 at 22:13

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.