Lab 3

[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.

  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 1 or 2 proceed as follows. Begin by prompting the user for two complex numbers.
  4. Compute C3 = C1+C2.
  5. 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.
  6. 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.^n  n. Use the following command to plot y:
    plot(y)  
    xlabel(’Real’)  
    ylabel(’Imaginary’)  
    grid

    Explain what you see.

  7. 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.^n  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.