A contour line of a function of two variables is a curve along which the function has a constant value. Contour lines are used for creating contour maps by joining points of equal elevation above a given level, such as mean sea level.
MATLAB provides a contour function for drawing contour maps.
Example
Let us generate a contour map that shows the contour lines for a given function g = f(x, y). This function has two variables. So, we will have to generate two independent variables, i.e., two data sets x and y. This is done by calling the meshgrid command.
The meshgrid command is used for generating a matrix of elements that give the range over x and y along with the specification of increment in each case.
Use the meshgrid
function to generate matrices X
and Y
. Create a third matrix, Z
, and plot its contours.
x = linspace(-2*pi,2*pi); y = linspace(0,4*pi); [X,Y] = meshgrid(x,y); Z = sin(X)+cos(Y); figure contour(X,Y,Z)
No comments:
Post a Comment