I am trying to evaluate the derivative of a function at a point (3,5,1) in Mathematica. So, thats my input:
In[120]:= D[Sqrt[(z + x)/(y - 1)] - z^2, x]
Out[121]= 1/(2 (-1 + y) Sqrt[(x + z)/(-1 + y)])
In[122]:= f[x_, y_, z_] := %
In[123]:= x = 3
y = 5
z = 1
f[x, y, z]
Out[124]= (1/8)[3, 5, 1]
As you can see I am getting some weird output. Any hints on evaluating that derivative at (3,5,1) please?
The result you get for
Out[124]leads me to believe thatfwas not cleared of a previous definition. In particular, it appears to have what is known as anOwnValuewhich is set by an expression of the form(Note the lack of a colon.) You can verify this by executing
which returns
Unfortunately,
OwnValuessupersede any other definition, like a function definition (known as aDownValueor, its variant, anUpValue). So, definingwould cause
g[5]to evaluate to5[5]; clearly not what you want. So,Clearany symbols you intend to use as functions prior to their definition. That said, your definition offwill still run into problems.At issue, is your use of
SetDelayed(:=) when definingf. This prevents the right hand side of the assignment from taking on a value untilfis executed later. For example,returns
6, instead. This occurs because6was last result generated, andfis effectively a synonym of%. There are two ways around this, either useSet(=)which returns
16, as expected, or ensure that%is replaced by its value beforeSetDelayedgets its hands on it,