How to evaluate df function in the following code sample?
f[x_,y_]:=Sqrt[x^4-4x^2 y^2]
df[x_,y_,dx_,dy_]:=Sqrt[(D[f[x,y],x]dx)^2+(D[f[x,y],y] dy)^2]
df[1,2,0.2,0.3]
General::ivar: 1 is not a valid variable. >> General::ivar: 2 is not a valid variable. >>
:=
says to evaluate the right hand side later when the function is called. Nextdf[1,2,0.2,0.3]
sets x equal to 1 and y equal to 2. Next evaluate the right hand side doingD[f[1,2],1]
and you don't know how to differentiate with respect to 1. Same for 2. If you change the:=
to=
in your definition of thedf
function and you clear all definitions or restart Mathematica then the right hand side is evaluated beforedf[1,2..2,.3]
and the error message goes away. But you must be very careful with this to be certain that the answer is correct. $\endgroup$:=
and=
. It will help you in other contexts too. $\endgroup$