Preceding an operator with a period indicates an

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: an operator with a period . indicates an array or element-by-element operation. For example, if X = 1 2 3] and Y = 4 5 6] then X: Y = 4 10 18]. Notice that the usual vector product X Y is unde ned. The Matlab object ones(m,n) is useful if you want to add or subtract a constant from each element in a vector. ones(m,n) is an m-by-n matrix of ones. Using the vector X from the last example, you write the expression X + 2 as follows in Matlab notation. X + 2 * ones(1,3) The dimension of ones vector must match the other vectors in the computation. The command size(A) returns the dimension of a vector or matrix A. On-line Help Matlab has on-line help for all its commands. For example, try any of these commands: help print help help help general Making Plots Matlab provides a variety of functions for displaying data as 2-D or 3-D graphics. For 2-D graphics, the basic command is: plot(x1, y1, 'line style', x2, y2, 'line style'...) 2 This command plots vector x1 versus vector y1, vector x2 versus vector y2, etc. on the same graph. Other commands for 2-D graphics are: polar, bar, stairs, loglog, semilogx, and semilogy. For 3-D graphics, the most commonly used commands are: plot3(x1, y1, z1, 'line style', x2, y2, z2, 'line style'...) contour(x,y,Z) mesh(x,y,Z), surf(x,y,Z) The rst statement is a three-dimensional analogue of plot() and plots lines and points in 3-D. The second statement produces contour plots of the matrix Z using vectors x and y to control the scaling on the x- and y- axes. For surface or mesh plots, you use the third statement where x, y are vectors or matrices and Z is a matrix. Other commands available for 3-D graphics are: pcolor, image, contour3, ll3, cylinder, and sphere. Example 1: Plot y...
View Full Document

Ask a homework question - tutors are online