User Tools

Site Tools


supp:octave:contrib:surface_plot:start

This is an old revision of the document!


Octave: Surface, Contour (Isolines), Gradient

Download the script by klicking on the file name in the box header. Execute the file in Octave. Compare the results with the gradients determined in the lecture.

surf_cont_grad.m
% surf_cont_grad
% Plot surface, contour lines and gradient of functions of two variables
% 2015-04-22, Rolf Becker
 
x = [-2:2]
y = [-1:1]
 
[XX,YY] = meshgrid(x,y) % explain
 
%break
 
x = [-2:0.1:2]; % x values
y = [-1:0.1:1]; % y values
 
[X,Y] = meshgrid(x,y);
 
Z=(X.^2).*Y-2*Y; % the function f(x,y)
 
[dX,dY] = gradient(Z);
 
figure(1)
surf(X,Y,Z)
xlabel("x"); ylabel("y");zlabel("f(x,y)")
 
figure(2)
contour(X,Y,Z)
xlabel("x"); ylabel("y");title("Contour lines of f(x,y)")
grid on 
 
figure(2)
contour(X,Y,Z)
xlabel("x"); ylabel("y");title("Contour lines of f(x,y)")
grid on 
 
figure(3)
contour(X,Y,Z)
hold on
quiver(X,Y,dX,dY)
hold off
xlabel("x"); ylabel("y");title("Gradient f(x,y)")
grid on
supp/octave/contrib/surface_plot/start.1460624977.txt.gz · Last modified: 2016/04/14 09:09 by admin