Question

In: Advanced Math

In Matlab: Any complex number z=a+bi can be given by its polar coordinates r and θ,...

In Matlab:

Any complex number z=a+bi can be given by its polar coordinates r and θ, where r=|z|=sqrt(a^2+b^2) is the magnitude and θ= arctan(ba) is the angle. Write a function that will return both the magnitude r and the angle θ of a given complex numberz=a+bi. You should not use the built-in functions abs and angle. You may use the built-in functions real and imag.

Solutions

Expert Solution

MATLAB Script (Run it as a script, not from command window):

close all
clear
clc

fprintf('Example 1\n-------------------------------------------\n')
c = 2+3i
[r,theta] = polar_coord(c)

fprintf('\nExample 2\n-------------------------------------------\n')
c = -2+3i
[r,theta] = polar_coord(c)

fprintf('\nExample 3\n-------------------------------------------\n')
c = -2-3i
[r,theta] = polar_coord(c)

fprintf('\nExample 4\n-------------------------------------------\n')
c = 2-3i
[r,theta] = polar_coord(c)

function [r,theta] = polar_coord(c)
% c - complex number, a + bi
a = real(c); b = imag(c);
r = sqrt(a^2 + b^2);
if a > 0 && b > 0
theta = atan(b/a);
else
if a < 0 && b > 0
theta = pi - atan(b/-a);
else
if a < 0 && b < 0
theta = atan(-b/-a) - pi;
else
theta = -atan(-b/a);
end
end
end
end

Output:

Example 1
-------------------------------------------
c =
2.0000 + 3.0000i
r =
3.6056
theta =
0.9828

Example 2
-------------------------------------------
c =
-2.0000 + 3.0000i
r =
3.6056
theta =
2.1588

Example 3
-------------------------------------------
c =
-2.0000 - 3.0000i
r =
3.6056
theta =
-2.1588

Example 4
-------------------------------------------
c =
2.0000 - 3.0000i
r =
3.6056
theta =
-0.9828


Related Solutions

The Cartesian coordinates of a point are given. (a)    (−3, 3) (i) Find polar coordinates (r, θ)...
The Cartesian coordinates of a point are given. (a)    (−3, 3) (i) Find polar coordinates (r, θ) of the point, where r > 0 and 0 ≤ θ < 2π. (r, θ) = (ii) Find polar coordinates (r, θ) of the point, where r < 0 and 0 ≤ θ < 2π. (r, θ) = b. (5,5sqrt(3)) (i) Find polar coordinates (r, θ) of the point, where r > 0 and 0 ≤ θ < 2π. (r, θ) = (ii) Find...
Two vectors in polar coordinates (R, θ) are given byV1 = (5.0, 125°) and V2 =...
Two vectors in polar coordinates (R, θ) are given byV1 = (5.0, 125°) and V2 = (4.0, 260°). Find the sum V1 + V2 in polar coordinates. Give the answer to 2 significant figures for the magnitude and to the nearest degree in angle. Hint: first convert the vectors to Cartesian form and add them to get the resultant vector. Then convert this resultant vector to polar form
Convert the complex number to polar form rcisθ. (a) For z=−1+i the modulus of zis r=,...
Convert the complex number to polar form rcisθ. (a) For z=−1+i the modulus of zis r=, and the principal argument is θ =. (b) For z=−33‾√−3i the modulus of zis r=, and the principal argument is θ =. (c) For z=−2 the modulus of zis r=, and the principal argument is θ =. (d) For z=−3i the modulus of zis r=, and the principal argument is θ= .
The Cartesian coordinates of a point are given. (a) (2, −5) (i) Find polar coordinates (r,...
The Cartesian coordinates of a point are given. (a) (2, −5) (i) Find polar coordinates (r, θ) of the point, where r > 0 and 0 ≤ θ < 2π. (r, θ) = (ii) Find polar coordinates (r, θ) of the point, where r < 0 and 0 ≤ θ < 2π. (r, θ) = (b) (-2, −2) (i) Find polar coordinates (r, θ) of the point, where r > 0 and 0 ≤ θ < 2π. (r, θ) =...
3. Geodesics in R2 : Consider 2D flat space in polar coordinates r and θ. Find...
3. Geodesics in R2 : Consider 2D flat space in polar coordinates r and θ. Find the curves parametrized by r(s) and θ(s) that satisfy the geodesic equation, and show that they correspond to straight lines in R2
The unit vector (in cylindrical coordinates) parallel to the z-axis at Q (r = 5, θ...
The unit vector (in cylindrical coordinates) parallel to the z-axis at Q (r = 5, θ = π/2, ϕ =1.5π) is
In java: A complex number is a number in the form a + bi, where a...
In java: A complex number is a number in the form a + bi, where a and b are real numbers and i is sqrt( -1). The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas: a + bi + c + di = (a + c) + (b + d)i a + bi - (c...
Find the slope of the tangent line to the given polar curve at the point specified by the value of θ. r = 1 + 2 cos θ, θ = π/3
Find the slope of the tangent line to the given polar curve at the point specified by the value of θ. r = 1 + 2 cos θ, θ = π/3
What is the area inside the polar curve r = 1 , but outside the polar curve r = 2 cos θ ?
What is the area inside the polar curve r=1, but outside the polar curve r=2cosθ?
Plot the point whose polar coordinates are given. Then find the Cartesian coordinates of the point...
Plot the point whose polar coordinates are given. Then find the Cartesian coordinates of the point b. (2, π/4) c.(−3, −π/6)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT