# Plotting a function with 2 dependent variables

123 views (last 30 days)
Gekkouga on 7 Jan 2021
Commented: Star Strider on 7 Jan 2021
Hi,
I have a function a variable (z) which is dependent on two other variables (x,y). The function looks like z = f(x,y)
x ranges from 0 to 100 and y ranges from 0 to 1. I use linspace to divide both x and y into 100 values.Through nested loop substitution, I get 100 x 100 values for z.
How do I plot z against x and y? If I use plot3 I get an error saying dimensions don't match.
Thanks

Star Strider on 7 Jan 2021
Use the mesh or surf functions. Other options are contour, and waterfall, depending on the result you want.
##### 2 CommentsShowHide 1 older comment
Star Strider on 7 Jan 2021
As always, my pleasure!

### More Answers (1)

Mischa Kim on 7 Jan 2021
[x,y] = meshgrid(-10:0.1:10);
z = sin(x).*cos(y);
plot3(x,y,z)

### Categories

Find more on Surface and Mesh Plots in Help Center and File Exchange

R2020a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by