Вы находитесь на странице: 1из 2

Lab Experiment 2: Script, Functions and Flow Control 

Objectives:
At the end of the experiment, the should can:
 Write M‐File scripts ins MATLAB
 Create functions in MATLAB
 Use flow control commands in MATLAB

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

Overview:
Refer to the accompanied lecture.

Exercise 1:
Use MATLAB to generate the first 100 terms in the sequence a(n) define recursively by
1 ∗ ∗ 1
with p = 2.9 and a(1) = 0.5.
After you obtain the sequence, plot the sequence.

Exercise 2:
MATLAB M‐file function:
Consider the following equation
0
sin 1 ∗
1
a. Write a MATLAB M‐file to obtain numerical values of y(t). Your function must take y(0),
ζ, ωn, t and θ as function inputs and y(t) as output argument.
b. Write a second script m‐file to obtain the plot for y(t) for 0 < t < 10 with an increment of
0.1, by considering the following two cases:
Case 1: y(0) = 0.15 m, ωn = √2 rad/sec, ζ = 3/(2√2) and θ = 0;
Case 2: y(0) = 0.15 m, ωn = √2 rad/sec, ζ = 1/(2√2) and θ = 0;
Hint: When you write the function you would require element‐by‐element operator.

Exercise 3:
MATALB Flow Control
Use ‘for’ or ‘while’ loop to convert degrees Fahrenheit (Tf) to degrees Celsius using the following

equation ∗ 32. Use any starting temperature, increment and ending temperature

(example: strating temp – 0, increment temp = 10, ending temp = 200).




Submit the MATLAB m‐file together with the results.

Assignment and Research:

AS 3.1: Write a MATLAB program that will calculate the product of two numbers using successive
addition.

AS 3.2: For a positive integer n, let A(n) be an nxn matrix with entries aij = 1/(i + j – 1). For example,
1 1/2 1/3
3 1/2 1/3 1/4
1/3 1/4 1/5
The eigenvalues of A(n) are all real numbers. Write a script M‐file that prints the largest eigenvalue
of A(500), without any extraneous output.

AS 3.3: Write a script M‐file that draws a bulls‐eye pattern with a central circle colored red,
surrounded by alternating circular strips (annuli) of white and black, say ten of each. Make sure the
final display shows circles, not ellipses.

Вам также может понравиться