Graphics Programs Reference

In-Depth Information

The (
x, y
) pairs can be split into two matrices:

1234

1234

1234

1234

1111

2222

3333

4444

x
=

;
y
=

.

The matrix
x
varies along its columns and
y
varies down its rows. We

define the surface
z
:

z
=
x
2
+
y
2
;

which is the distance of each (
x, y
) point from the origin (0
,
0). To

calculate
z
in matlab for the
x
and
y
matrices given above, we begin

by using the
meshgrid
function, which generates the required
x
and
y

matrices:

>> [x,y] = meshgrid(1:4)

x=

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

y=

1

1

1

1

2

2

2

2

3

3

3

3

4

4

4

4

N
ow we s
imply convert our distance equation to matlab notation;
z
=

x
2
+
y
2
becomes:

>> z = sqrt(x.^2 + y.^2)

z=

1.4142

2.2361

3.1623

4.1231

2.2361

2.8284

3.6056

4.4721

3.1623

3.6056

4.2426

5.0000

4.1231

4.4721

5.0000

5.6569