How can I plot a function with two variables in Octave or Matlab?

Plotting a function of two variables would normally mean a 3-dimensional plot – in MATLAB you would use the function plot3 for that. To plot your function f(x,y) in the interval [-10,10] for both X and Y, you could use the following commands:

x = [-10:.1:10];
y = [-10:.1:10];
plot3(x, y, x.^2 + 3*y)
grid on

Leave a Comment