Lab
Experiment 1: Introduction to MATLAB
Objectives:
This experiment provides the students the following:
An introduction to mathematical programming using MATLAB
Tutorial on how to define variables, matrices, and plot results and write simple
MATLAB codes
Tutorials of polynomials, script writing, and programming aspect of MATLAB from
control systems view point.
List of Equipment/Software
The following equipment/software is required:
MATLAB
Deliverables:
A complete lab report including the following:
Summarized learning outcomes
MATLAB commands and their results should be reported properly
Introduction to MATLAB
Refer to the accompanied lecture.
Exercise 1.1:
Use MATLAB commands to obtain the following
a. Extract the fourth row of the matrix generated by magic (6)
b. Show the results of ‘x’ multiply by ‘y’ and ‘y’ divides by ‘x’. Given x = [0:0.1:1.1] and y =
[10:21]
c. Generate random matrix ‘r’ of size 4 by 5 with number varying between -8 and 9.
Exercise 1.2:
Use MATLAB commands to get exactly as the figure shown below.
x = pi/2:pi/10:2*pi
y = sin(x)
z = cos (x)
Exercise 1.3:
Use MATLAB command that would plot a circle with a diameter of 20 using the following equations:
x = r * sin(t)
y = r* cos(t) where t is from 0 to 2pi
Assignment:
AS 1.1: Create a MATLAB vector called sig1 representing approximately 5 cycles of the sinusoidal
voltage waveform cos(2πft) where the frequency is 1000* your seat number. Use at least 20 samples
per sinusoidal cycle. Plot sig1.
AS 1.2: Factor the polynomial x4 – y4.
AS 1.3: Use either solve or fzero, as appropriate, to solve the following equations:
(a) 8x + 3 = 0 (exact solution)
(b) 8x + 3 = 0 (numerical solution to 15 places)
(c) x3 + px + q = 0 (Solve for x in terms of p and q)
(d) ex = 8x − 4 (all real solutions). It helps to draw a picture irst.
AS 1.4: Use plot and/or ezplot, as appropriate, to graph the following functions:
(a) y = x3 − x for −4 ≤ x ≤ 4.
(b) y = sin(1/x2) for −2 ≤ x ≤ 2. Try this one with both plot and ezplot.
Are both results “correct”? (If you use plot, be sure to plot enough
points.)
(c) y = tan(x/2) for −π ≤ x ≤ π, −10 ≤ y ≤ 10 (Hint: First draw the plot;
then use axis.)
(d) y = e−x2 and y = x4 − x2 for −2 ≤ x ≤ 2 (on the same set of axes).
AS 1.5: Plot the functions x4 and 2x on the same graph and determine how many times their graphs
intersect. (Hint: You will probably have to make several plots, using intervals of various sizes, to find
all the intersection points.) Now find the approximate values of the points of intersection using fzero.