In polar coordinates a two-dimensional vector is y given by its radius and angle
ID: 3887055 • Letter: I
Question
In polar coordinates a two-dimensional vector is y given by its radius and angle (r, theta). Write a user- defined MATLAB function that adds two vectors that are given in polar coordinates. For the function name and arguments use [r th] = AddVecPol(r1, th1, r1, th2), where the input arguments (r_1, theta_1), and (r_2, theta_2), and the output arguments are the radius and angle of the result. Use the function to carry out the following additions: (a) r_1 = (5, 23 degree), r, -(12, 40 degree). (b) r1 = (6, 80 degree), r_2= (15, 125 degree).Explanation / Answer
program:-
function [r, th]=AddVecPol(r1,th1,r2,th2)
%convert points to rectangular coordinates
x1=r1*cosd(th1);
y1=r1*sind(th1);
x2=r2*cosd(th2);
y2=r2*sind(th2);
%adding to rectangular coordinates
x=x1+x2;
y=y1+y2;
%conver resultant point polor coordinates
r=sqrt(x^2+y^2);
th=atand(y/x);
if(th<0)
th=180+th;
end
end
output:-
>> [r th]=AddVecPol(5,23,12,40)
r =
16.8451
th =
35.0215
>> [r th]=AddVecPol(6,80,15,125)
r =
19.7048
th =
112.5663
>>