Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

TEST 3 ENGG 010, Spring 2017 120 total points 100 computed 20 bonus points I. Pr

ID: 2082696 • Letter: T

Question

TEST 3 ENGG 010, Spring 2017 120 total points 100 computed 20 bonus points I. Problem Solving and Programming using MATLAB Functions and Scripts (5 questions write and save the following m files then email as attachments using Hofstra Blackboard 1. Copoints Custom MATLAB fiinction problem Convert the given script into a MATLAB function called Car2Pol Name with 2 inputs (x and y) and 2 outputs (r and a that converts x and y Cartesian (rectangular) coordinates into the polar coordinate values: r radius of a circle with center at the origin (0,0) and a degrees from the positive horizontal x axis to the current location in a counterclockwise direction. $4 Clear Previous clear cle 44 Given (x,y Senter LO 012 cesses. in (0,0) of the circle the T10 Center of the center 12 k Center component of the center aces trx-h)/r) 150/pi: degree angle using x 15 y asin (ty k)/2) 180/pia degree angle using 3 17 if y 15 150 abs Kay) a 360 ay: 25 end Resalts 1): disp (t ther the ostputs are: and a (a) deg ees. Window Ir the inputs are: --3 and y 2, then the outputs are: r 3.6056 and a 256.3089 degrees Question 1: CA,B] Rec2Pol Name(17 -2],[7 41); What are the values of A and B?

Explanation / Answer

Copy the following code to a new function file in MATLAB. Name the file Car2Pol_Name.m.

function [r,a] = Car2Pol_Name(x,y)

Center = [0 0];
h = Center(1);
k = Center(2);
r = (((x-h).^2)+((y-k).^2)).^0.5;
ax = acos((x-h)./r)*180/pi;
ay = asin((y-k)./r)*180/pi;
N = length(x);
for i = 1:N
if y(i) >= 0
a(i) = ax(i);
else
if x(i) <= 0
a(i) = 180+abs(ay(i));
else
a(i) = 360+ay(i);
end
end
end
end

Copy the following code to a new script in MATLAB.

close all; clear all; clc;
% The function name is incorrectly mentioned in Question # 1
[A,B] = Car2Pol_Name([7 -2],[7 4]);
A
B