[PDF]
ECE 201: Introduction to Electrical Engineering II
Prof. B.-P. Paris
Lab 3: Programming in MATLAB
The objective of this lab is to write a Matlab script M-file that implements the functionality described below. Store your program in a file named Lab3.m.
Read the user’s input and proceed according to his choice. Should the user enter anything other than 0, 1, or 2, display an error message and redisplay the menu.
Allow the user to continue from this dialog only after he selected either 1 or 2.
Proceed to prompt the user for the magnitude and phase of the first complex number. Check that the magnitude is positive. Construct a complex number C1 from the user’s input. Be sure to interpret the phase according to the preference expressed by the user. Don’t forget to convert to radians if the user indicated a preference for degrees. Display the complex number C1 in rectangular coordinates, e.g., display a line like
where x and y are the the real and imaginary parts of C1.
Prompt the user for a second complex number and store it as C2. Ensure that C1 and C2 are different. Display the number C2 in rectangular form.
Prompt the user if he prefers the results in polar form to show the phase in radians or degrees. The corresponding menu might look like this
Allow the user to continue from this dialog only after he selected either 1 or 2.
Compute the magnitude and phase of each of the two numbers and display the result like this
where r1, r2, phi1, phi2 are the magnitudes and phases you computed.
n. Use the
following command to plot y:
Explain what you see.
For your final report, turn in your well-commented Matlab program Lab3.m.
Attach a plot that shows C3.
n with an explanation of what you see. Also,
execute your program once while capturing output to a diary file and attach the
diary file.
The report is due one week after this lab.