f[x_, y_, z_] := x^2 + y^3 + xy^2 + 4 z
 D[f[x, y, z], x]

gives the result 2 x + 6 x^5 which is obviously wrong. What could be wrong with my code?

also if I try

f[x_, y_, z_] := x^2 + y^3 + x*y^2 + 4 z
D[f[x, y, z], x]

the ansewer is another wrong

2 x + 5 x^4 + 6 x^5

is my error syntax? thanks


closed as off-topic by MarcoB, Coolwater, Henrik Schumacher, QuantumDot, corey979 Jun 21 '18 at 0:17

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Henrik Schumacher, QuantumDot, corey979
  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – MarcoB, Coolwater
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    $\begingroup$ Restart the kernel. Something is going wrong here; maybe a hanging definition of y or z. Morever xy^2 should probably be x y^2... $\endgroup$ – Henrik Schumacher Jun 20 '18 at 7:05
  • 5
    $\begingroup$ the most likely explanation is that you defined y=x^2 and z=0 somewhere before. Use Clear[x,y,z] and try your second code again. $\endgroup$ – halirutan Jun 20 '18 at 7:26
  • 2
    $\begingroup$ In addition, as you may already have noticed, xy^2 is the square of the variable xy, rather than xtimes the squared y. You need to either write x*y^2, or x y^2, according to your liking. $\endgroup$ – Alexei Boulbitch Jun 20 '18 at 8:47

Both of those functions work normally on my computer. As @halirutan has suspected, the reason seems to be that you have made some definitions on y and z, thus giving the wrong result.


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