Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Student Name:

Student ID:

REVIEW
Guideline: Save your assignment in PDF file under the name StuName_StuID

Part 1 – If/Switch Statements: (Total 30 points)


Code these following functions with If/Switch Statement
−𝑥 2 , 𝑥≤0
1. 𝑓(𝑥) = { 3, 0<𝑥<3 (10 points)
𝑥, 𝑥≥3
2.

(10 points)

3. Plot 𝑓(𝑥) and replot 𝑥(𝑡) from your MATLAB code on Question 1 & 2
(10 points)
Part 2: For and While-Loop (Total 30 points)
Compute these following functions by two methods: For-Loop and While – Loop
𝑥𝑘
1. 𝑓1 (𝑥, 𝑛) = ∑𝑛𝑘=1 (10 points)
𝑘
2. 𝑓2 (𝑥, 𝑛) = ∑𝑛−1
𝑘=0 𝑥
𝑘
(10 points)
3. Use user-defined function to code these two functions with inputs of
𝑥 and 𝑛. Then, plot 2 figures of 𝑓1 (0.5, 𝑛) and 𝑓2 (0.5, 𝑛) (10 points)

Part 3 – Matrices (Total 30 points)


Write all in one code as following steps: (5 points/each question)
1. Generate an uniform distributed integer matrix 𝑨 with size 5 x 5 such that
all elements are in the range [0, 20].
2. Generate an uniform distributed real-value row vector 𝒃 with size 1 x 5
such that all elements are in the range [-10, 10].
3. Insert the vector 𝒃 below the second row of the matrix 𝑨.
4. Delete the fourth column of the matrix 𝑨 (after inserting 𝒃 in question 3).
5. Find the minimum and maximum value with their index from all elements
in the matrix 𝑨.
6. Find all elements in the matrix 𝑨 larger than 5.

You might also like