0
$\begingroup$

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}]

enter image description here

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}]
$\endgroup$
3
  • 2
    $\begingroup$ Do you want this ContourPlot[w[x, y, int[x, y]], {x, 0, 8}, {y, 0, 8}] $\endgroup$
    – Hubble07
    Commented Sep 15, 2014 at 14:10
  • $\begingroup$ I want $w(x,y)$ with the replaced value of $z(x,y)$ $\endgroup$
    – user44840
    Commented Sep 15, 2014 at 14:17
  • 1
    $\begingroup$ @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. $\endgroup$
    – Mr.Wizard
    Commented Sep 15, 2014 at 14:39

2 Answers 2

3
$\begingroup$

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}]
$\endgroup$
4
  • $\begingroup$ That's perfect. $\endgroup$
    – user44840
    Commented Sep 15, 2014 at 14:32
  • 3
    $\begingroup$ but this is exactly what i said in the comments to the OP $\endgroup$
    – Hubble07
    Commented Sep 15, 2014 at 14:32
  • 1
    $\begingroup$ +1 But please see that you should't interpolate from 0 to 5 and then plot the interpolated function from 0 to 8. $\endgroup$
    – eldo
    Commented Sep 15, 2014 at 14:35
  • $\begingroup$ @eldo good point. I didn't notice this... $\endgroup$
    – Igor Rivin
    Commented Sep 15, 2014 at 14:37
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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