Chapter 4
Chapter 4
Author
image here
Converting Polar Coordinates to Rectangular
Converting Rectangular Coordinates to Polar
Plotting Polar Coordinates
Outline
Polar and Rectangular Coordinates
3
Conversion Between Polar and Rectangular
X = r cosθ r=
Y = r sinθ θ = tan-1()
4
Converting Between Polar And Cartesian in Matlab
>>[x,y] = pol2cart(pi/4,1)
x = ?
y = ?
>>[theta,r] = cart2pol(0,-4)
theta = ?
r = ?
[x,y] = pol2cart(theta,r)
[theta,r] = cart2pol(x,y)
angle comes first
5
Exercise
Calculate the
cartesian coordinates
of the two red points •
θ is expressed in radians
6
Polar Command in Matlab
7
Example 1
Solution:
Create a script file: example1.m
8
9
Example 2 Solution:
Find the polar coordinates of a >>x=3;
point (x,y) of your choice using >>y=4;
Matlab as a calculator >>r=sqrt(x^2+y^2);
>>theta=atan2(y,x); % in radians
>>theta = theta *180/pi % in degrees
Answer:
r=?
theta=?
10
Example 3 Solution:
Find the rectangular coordinates of >>r=5;
the point (5,53°) using Matlab as a >>theta=53*pi/180; %convert to radians
calculator >>x = r * cos(theta);
>>x = r * sin(theta);
Answer:
x=3
y=4
11
Example 3 Solution:
Repeat Example 1 and plot the Open a script file example1d.m
given points using the polar to >>r=[5 5 3 3 3];
rectangular conversion relation. >>theta=[0 60 180 300 -30]*pi/180;%to rad
Add the two examples on one plot. >>polar(theta,r,’x’);
>>hold on;
>>x=r .* cos(theta); % from polar to rectangular
>>plot(x,y, ‘o’);
12
13
Example 5
Solution:
Open a script file example5.m
14
15
Example 6
Solution:
Open a script file example6.m
16
17
Area in Polar Coordinates (from calculus II)
Example 7:
Find the area bounded by the curves r = 2 sinθ, θ1 = 45°, θ2 = 135°
and the origin
Show all curves in one plot
18
Solution (1/2)
>>r=linspace(0,2);
>>theta=(45*pi/180)*ones(size(r));
>>polar(theta,r,’b’);
>>hold on;
>>r=linspace(0,2);
>>theta=(135*pi/180)*ones(size(r));
>>polar(theta,r,’g’);
19
Solution (2/2)
Solution
1-plot the two curves:
Open example8.m
>>theta=linspace(0,2*pi)
>>r=2*ones(size(theta));
>>polar(theta,r,’r’);
>>hold on;
>>r=3+2*sin(theta);
>>polar(theta,r);
21
Solution (2/2)