MATLAB: 3D surfaces from known equation

3d surface;graphs

I need to plot a 3D surface from a known equation. Z= (1-p)/(X-Y). I want to vary X,Y and p continuously eg X = [0.*.100] I am getting an error to the effect that matrix sizes don't match while trying to use the surf function.Any help/ ideas?

Best Answer

N = 10 ; % can be changed
x = linspace(x0,x1,N) ;
y = linspace(y0,y1,N) ;
[X,Y] = meshgrid(x,y) ;
p = 1:10 ; % your p values
D = X-Y ;
for i = 1:length(p)
Z = (1-p(i))./D ;
surf(X,Y,Z) ;
hold on
end
[x0,x1] and [y0,y1] are your limits of x and y respectively.
Related Question