You are on page 1of 22

ENE 206

Matlab 4
Coordinate systems

Vector and scalar quantities


Vector

A or A or A

scalar

Vectors - Magnitude and direction


1. Cartesian coordinate system (x-, y-, z-)

Vector operation in Matlab


Cartesian coordinate system

A Ax a x Ay a y Az a z
Example
A = 1ax + 2ay + 3az
>> A = [1 2 3]
Find the magnitude of A
>> norm(A)
or >> abs(A)

Scalar product

AB = |A||B|cos = ABcos
Equivalent definition
AB = AxBx +AyBy +AzBz
Scalar projection

A B
projB A
B

example_101

Cross product

A x B = |A||B|sin = ABsin
Equivalent definition
a x


A B Ax
Bx

a y

a z

Ay

Az

By

Bz

Ay Bz Az By a x Az Bx Ax Bz a y Ax By Ay Bx a z

Matlab command is >> cross(A,B)

Cross product (cont.)

example_102

The cross product of the two vectors A = 2ax + 1ay + 0az and B = 1ax + 2ay + 0az is
shown. The vector product of the two vectors A and B is equal to C = 0ax + 0ay + 3az.

Scalar triple product

A (B x C)=B (C x A) = C (A x B)
>> dot(A, cross(B,C))

Vector triple product

A x (B x C)=B(A C) -C(A B)
>> cross(A, cross(B,C))

Volume defined by three vectors


originating at a point

v = area of the base x height


v = (|A x B|)(C an)
where an = (A x B)/|A x B|

A = [3 0 0];
B = [0 2 0];
C = [0 2 4];
deltav = C(A x B)
example_103

Cylindrical coordinate system (, , z)

A A a A a Az a z

orthogonal point (, , z)
= a radial distance (m)
= the angle measured from
x axis to the projection of the
radial line onto x-y plane
z = a distance z (m)

Transformation of a vector in cylindrical


coordinates to one in Cartesian coordinates
Ax = Aax
Ay = Aay
Az = Aaz
where A is in cylindrical coordinates and assumed
constant.

Dot products of unit vectors in Cartesian and


cylindrical coordinate systems
a

a z

a x

cos

-sin

a y

sin

cos

a z

Conversion of variables between Cartesian


and cylindrical coordinates
A conversion from
P(x,y,z) to P(,, z)

x2 y 2

A conversion from
P(,, z) to P(x,y,z)

x cos

y
tan
x

y sin
zz

zz
Matlab command
[ph,rh,z] = cart2pol(x,y,z)

Matlab command
[x,y,z] = pol2cart(ph,rh,z)

The transformation of a vector A = 3ax + 2ay + 4az in


Cartesian coordinates into a vector in cylindrical
coordinates. The unit vectors of the two coordinate
systems are indicated.

figure_112

Cylinder creation in Matlab


>> [x,y,z] = cylinder(r,n);
>> surf (x,y,z)
where r = radius
n = number of pts
along the circumference.

1
0.8
0.6
0.4
0.2
0
2
1

2
1

-1

-1
-2

-2

Spherical coordinate system (, , )

A Ar a r A a A a

figure_113

orthogonal point (r,, )


r = a radial distance from the
origin to the point (m)
= the angle measured from
the positive z-axis (0 )
= an azimuthal angle,
measured from x-axis (0
2 )

Transformation of a vector in spherical


coordinates to one in Cartesian coordinates
Ax = Aax
Ay = Aay
Az = Aaz
where A is in spherical coordinates and assumed
constant.

Dot products of unit vectors in Cartesian and


spherical coordinates
ar

a x

sincos

coscos

-sin

a y

sinsin

cossin

cos

cos

-sin

a z

Conversion of variables between Cartesian


and spherical coordinate systems
A conversion from
P(x,y,z) to P(r,, )
r x2 y 2 z 2
1

z
cos
r
1

y
tan
x

A conversion from
P(r,, ) to P(x,y,z)
x r sin cos
y r sin sin
z r cos

Matlab command
Matlab command
[th,phi,r] = cart2sph(x,y,z) [x,y,z] = sph2cart(th,phi,r)

Convert the Cartesian coordinate point P(3, 5, 9) to


its equivalent point in cylindrical and spherical
coordinates.

You might also like