ENGR 17 Assignment 3 Functions and Complex Numbers Due: Next Tues 10 points max (plus 1 extra credit) Drills: 1) Function Drills (4 points) 2) Complex Drills (2 points) Suppose we have four complex numbers, some in rectangular form others in polar form: a = 3 + 4i b= -5 + 6i c = 8<45 (This means a magnitude of 8 and an agle of 45 degrees) d = 12<250 Create a script file called complex.m. In this file use matlab to : I) Express these quantities in rectangular form: a+b a/b c c+d II) Express these quantities in polar form (magnitude and phase): a c/d ab a+c The easiest way is to represent a,b,c,d as complex numbers, do the math, and (for part II) convert the answer to polar form Applications: Do one or more of the following 1) (4 points) The robot arm from Assignment 1 takes two angle positions to move to a certain point in x,y space. Recall the formulas x = 10cos(Q1) + 10cos(Q1+Q2) and y = 10sin(Q1) + 10sin(Q1+Q2) where Q1 and Q2 are the angles of the base and elbow joint respectively. a) Using matlab, first make an m-file robotXY.m which contains function [x , y] = robotXY( th1, th2) that receives the two angles as parameters and returns the corresponding x,y position of the robot arm. b) Test your new function with the following statements: [x y] = robotXY( pi/2, pi/2) should return x = -10, y = +10 [x y] = robotXY( pi/6, 2*pi/3) should return x = 0, y = +10 and correct any errors you might have. c) Now make a new script m-file robotPlot.m that creates and draws the trajectory of the robot arm when Q1 goes from pi/3 to –pi/3 and Q2 goes from pi/2 to –pi/2. First construct the Q1 and Q2 vectors, then invoke [x y] = robotXY(Q1, Q2) to generate the corresponding x,y vectors, then plot(x,y) to create the plot. ADD title and axis labels! Save the plot as robotPlot.jpg 2) (5 points) For a more difficult challenge, develop the function [th1 , th2] = robotAngle(x,y) in other words, the reverse calculation. Lots of trig needed here. Use the test data from the previous problem: [Q1 Q1] = robotAngle( -10, 10 ) [Q1 Q1] = robotAngle( 0, 10 ) should return Q1 = pi/2 and Q2=pi/2 should return Q1 = pi/6 and Q2=2*pi/3 to test this function. Then make a script file robotAnglePlot.m that uses your robotAngle() function to determine the angles needed to move the arm along the parabolic path: x = [1:0.1:10]; y = 0.1*x.^2; Plot the angle vectors using plot(Q1,Q2) and save as robotAnglePlot.jpg. Verify the correct angles by feeding your calculated Q1, Q2 into the robotXY function and plot the x,y curve that results. It should be the same parabola you started with. 3) (2 points) To help in converting complex values between rectangular and polar form, create a function complex2Polar that takes a complex number argument and returns a complex number where the real part is the magnitude of the argument and the imaginary part is the phase in degrees. For example, complexRect2Polar( -5 + 12i) would return the value 13 – 112.6i which would indicate 13 < 112.6 degrees. Test this in your ComplexDrills script, then create the reverse function complexPolar2Rect such that complexPolar2Rect(13-112.6i) returns the orginal value -5+12i. 4) (4 points) A certain damped spring assembly (we saw animated in lecture) obeys the following complex response (Output/Input) formula a) Write a matlab function file response.m that computes function H = response( w ) where w is frequency in cycles/sec. using the following constant values: k = 26.5 N/m c = 11.9 N/(m/s) m = 10 kg and remember w must be converted to radians Note that H will be a complex number. b. Test your function: H = response(0.2) should return the value 1.5 – 0.7i c. Make sure your function is “vectorized” so it can be used with a vector of w data. This means use .^ to square the w vector and ./ to divide the numerator by the denominator d. Now make a script file responsePlot.m that uses your function to compute the response verses frequency as w varies from 0 to 2 Hz. Plot the magnitude of the complex response ( use the abs( ) function ) add title and axis labels, and save as respMag.jpg e. Also in responsePlot.m use the max function to determine the frequency where the response reaches its maximum and print out this value. Remember to take the index from max and provide it to w, such as w(index) to find the frequency that goes with the max response.
© Copyright 2026 Paperzz