7 Solved Problems on Electrical Engineering ll - Experiment | ECE 201, Lab Reports of Electrical and Electronics Engineering

Material Type: Lab; Professor: Paris; Class: Lab for Lecture 001; Subject: Electrical & Computer Enginrg; University: George Mason University; Term: Unknown 1989;

Typology: Lab Reports

Pre 2010

Uploaded on 02/12/2009

koofers-user-6sp
koofers-user-6sp 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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.
1. The program starts by presenting the user with the following menu of options:
Choose from the following menu:
Enter complex number in polar form (1)
Enter complex number in rectangular form (2)
End program (0)
Choice (0, 1, 2)? :
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.
2. If the user selects 0, end the program.
3. If the user selects 1or 2proceed as follows. Begin by prompting the user for two complex numbers.
If the user selected option 1, begin by prompting the user if he prefers to enter the phase of the
number in degrees or radians. The corresponding menu might appear like this
Enter phase in
degrees (1)
redians (2)
Choice (1, 2):
Allow the user to continue from this dialog only after he selected either 1or 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
C1=x+jy
where xand yare 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.
If the user selected option 2, prompt for the real and imaginary parts of the first number and
store the result as variable C1. Rep eat for a second complex number to be stored as C2. Ensure
that the two numbers are not identical.
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
Show phase in
degrees (1)
1
pf2

Partial preview of the text

Download 7 Solved Problems on Electrical Engineering ll - Experiment | ECE 201 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

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.

  1. The program starts by presenting the user with the following menu of options:

Choose from the following menu:

Enter complex number in polar form (1) Enter complex number in rectangular form (2) End program (0)

Choice (0, 1, 2)? :

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.

  1. If the user selects 0 , end the program.
  2. If the user selects 1 or 2 proceed as follows. Begin by prompting the user for two complex numbers.
    • If the user selected option 1 , begin by prompting the user if he prefers to enter the phase of the number in degrees or radians. The corresponding menu might appear like this Enter phase in

degrees (1) redians (2)

Choice (1, 2): 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 C1 = x + j y 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.

  • If the user selected option 2 , prompt for the real and imaginary parts of the first number and store the result as variable C1. Repeat for a second complex number to be stored as C2. Ensure that the two numbers are not identical. 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 Show phase in

degrees (1)

redians (2)

Choice (1, 2): 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 C1 has magnitude r1 and phase phi C2 has magnitude r2 and phase phi where r1, r2, phi1, phi2 are the magnitudes and phases you computed.

  1. Compute C3 = C1+C2.
  2. Plot the complex numbers C1, C2 and C3 in the complex plane. In other words, plot the real parts against the imaginary parts and label the axes Real and Imaginary, respectively. Use a red circle to plot C1, a blue square to plot C2, and a black diamond for C3.
  3. Construct the vector nn with elements from 0 to 20 with an increment of 1. Then, compute a second vector y with elements equal to C3.^nn. Use the following command to plot y:

plot(y) xlabel(’Real’) ylabel(’Imaginary’) grid

Explain what you see.

  1. Return to the beginning prompt so that the user can choose a different pair of complex numbers.

For your final report, turn in your well-commented Matlab program Lab3.m. Attach a plot that shows C3.^nn 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.