12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The (x, y) pairs can be split into two matrices:⎛⎞ ⎛1 2 3 4x = ⎜ 1 2 3 4⎟⎝ 1 2 3 4 ⎠ ; y = ⎜⎝1 2 3 41 1 1 12 2 2 23 3 3 34 4 4 4⎞⎟⎠ .The matrix x varies along its columns <strong>and</strong> y varies down its rows. Wedefine the surface z:z = √ x 2 + y 2 ;which is the distance <strong>of</strong> each (x, y) point from the origin (0, 0). Tocalculate z in matlab for the x <strong>and</strong> y matrices given above, we beginby using the meshgrid function, which generates the required x <strong>and</strong> ymatrices:>> [x,y] = meshgrid(1:4)x =1 2 3 41 2 3 41 2 3 41 2 3 4y =1 1 1 12 2 2 23 3 3 34 4 4 4Now we simply convert our distance equation to matlab notation; z =√x2 + y 2 becomes:>> z = sqrt(x.^2 + y.^2)z =1.4142 2.2361 3.1623 4.12312.2361 2.8284 3.6056 4.47213.1623 3.6056 4.2426 5.00004.1231 4.4721 5.0000 5.6569c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!