# Replace $z$ with interpolated function and plotting

I start off with this equation $z(x,y) = sin(xy)$. I create an interpolation from $0 < x < 5$ and $0 < y < 5$.

I then use this interpolation on a simple function $w(x,y) = x + y + z(x,y)$

I then do a contour plot of $w(x,y)$. Everything worked fine up to contour plot, and I'm not sure why.

Interpolating the data:

w[x_,y_,z_] := x + y + z
data1 = Flatten[ Table[{x, y, Sin[x y]}, {x, 0, 5, 1}, {y, 0, 5, 1}], 1]
int = Interpolation[data1]


Plotting to see if the interpolation works:

Plot3D[int[x, y], {x, 0, 8}, {y, 0, 8}]


Replacing $z$ with $int(x,y)$ to get $z(x,y)$ and plotting $w(x,y)$

z1[x_, y_] := z [x, y] /. int[x, y]
w1[x_, y_] := w[x, y, z] /. z1[x, y]
ContourPlot[w1, {x, 0, 8}, {y, 0, 8}]

• Do you want this ContourPlot[w[x, y, int[x, y]], {x, 0, 8}, {y, 0, 8}] Commented Sep 15, 2014 at 14:10
• I want $w(x,y)$ with the replaced value of $z(x,y)$ Commented Sep 15, 2014 at 14:17
• @user44840 If Hubble07's solution is what you wanted I'd like to know what you were attempting with /.. Not only does not not work (see my answer) but I can't figure out what you thought it would do. Understanding replacement rules is fundamental to using Mathematica well so I would like to help you reach that understanding. Commented Sep 15, 2014 at 14:39

I am not sure what you are trying to do exactly, but this works fine:

ContourPlot[w[x, y, z] /. z -> int[x, y], {x, 0, 8}, {y, 0, 8}]

• That's perfect. Commented Sep 15, 2014 at 14:32
• but this is exactly what i said in the comments to the OP Commented Sep 15, 2014 at 14:32
• +1 But please see that you should't interpolate from 0 to 5 and then plot the interpolated function from 0 to 8.
– eldo
Commented Sep 15, 2014 at 14:35
• @eldo good point. I didn't notice this... Commented Sep 15, 2014 at 14:37

Working backward:

1. You never gave w1 any arguments within ContourPlot (to fill its parameters).

2. The output of z1[x, y] is not a replacement rule.

3. The output of int[x, y] is not a replacement rule.

If you give the exact series of replacement that you wish to implement I can help you accomplish it.