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

Matlab

TP01

Objective: This TP relates to vector and matric by using MATLAB. It is an initial work to learn
how to use help for learning new functions. The built-in functions are written in bold and italic.

Note: Scripts must save in extension “.m”. To separate each exercise, you should use comment.

1. Scalar variables: Initialize these variables as follow


a. 𝑎 = 10
b. 𝑏 = 2.5 × 1023
c. 𝑐 = 2 + 3𝑖 where 𝑖 is imagine number
d. 𝑑 = 𝑒 2𝜋/3 (use exp, pi)

2. Vector variables: Initialize these variables as follow


a. 𝑎𝑉𝑒𝑐 = [3.14 19 9 26]

2.71
b. 𝑏𝑉𝑒𝑐 = [ 8 ]
28
182

c. 𝑐𝑉𝑒𝑐 = [5 4.8 … − 4.8 − 5] (numbers between 5 to -5 by decreasing 0.2)


d. 𝑑𝑉𝑒𝑐 = [100 100.01 … 100.99 101 ] (ue logspace)

3. Matric variables: Initialize these variables as follow

3 ⋯ 3
a. 𝑎𝑀𝑎𝑡 = [ ⋮ ⋱ ⋮ ] (a matric 9x9 for all 3, use ones or zeros)
3 ⋯ 3

1 ⋯ 0 0
0 0⋱ ⋱
b. 𝑏𝑀𝑎𝑡 = ⋮ 50 0 ⋮ (a matric 9x9 for all 0 but with these values
0⋱ ⋱ 0
[0 ⋯ 0 1]
[1 2 3 4 5 4 3 2 1] in diagonal, use zeros, diag)

1 11 ⋯ 91
2 12 ⋱ 92
c. 𝑐𝑀𝑎𝑡 = [ ]
⋮ ⋮ ⋱ ⋮
10 20 ⋯ 100
𝑁𝑎𝑁 𝑁𝑎𝑁 𝑁𝑎𝑁 𝑁𝑎𝑁
d. 𝑑𝑀𝑎𝑡 = [𝑁𝑎𝑁 𝑁𝑎𝑁 𝑁𝑎𝑁 𝑁𝑎𝑁] (a matric 3x4, use NaN)
𝑁𝑎𝑁 𝑁𝑎𝑁 𝑁𝑎𝑁 𝑁𝑎𝑁

13 −1 5
e. 𝑒𝑀𝑎𝑡 = [ ]
−22 10 −87

f. Initialize 𝑓𝑀𝑎𝑡, a matric 6x4 integers with random values between -5 and 5 (use
rand and floor or ceil)
4. Scalar equations: By using the variables created in exercise 1, calculate 𝑥, 𝑦, et 𝑧 :
1
a. 𝑥 = 1+𝑒 (−(𝑎−15)/6)
21 𝜋
b. 𝑦 = (√𝑎 + √𝑏) (use sqrt)
𝑎𝜋
c. 𝑧 = log (𝑅(𝑐) sin ( 3 )) /𝑐𝑐̅ where 𝑅 real part of complex number, 𝑐̅ a conjugate of
𝑐 (use real, conj, log)

5. Vector equations: By using the variables created in exercise 2, solve these equations
1 2 2
a. 𝑥𝑉𝑒𝑐 = √2𝜋2.52 𝑒 −𝑐𝑉𝑒𝑐 /(2×2.5 )
b. 𝑦𝑉𝑒𝑐 = √(𝑎𝑉𝑒𝑐 𝑇 )2 + 𝑏𝑉𝑒𝑐 2 (𝑎𝑉𝑒𝑐 𝑇 signify 𝑎𝑉𝑒𝑐 transpose)
c. 𝑧𝑉𝑒𝑐 = log10 (1/𝑑𝑉𝑒𝑐) (use log10)

6. Matric equation: By using the variables created in exercise 2&3, solve these equations
a. 𝑥𝑀𝑎𝑡 = (𝑎𝑉𝑒𝑐 ⋅ 𝑏𝑉𝑒𝑐) ⋅ 𝑎𝑀𝑎𝑡 2
b. 𝑦𝑀𝑎𝑡 = 𝑏𝑉𝑒𝑐 ⋅ 𝑎𝑉𝑒𝑐
c. 𝑧𝑀𝑎𝑡 = |𝑐𝑀𝑎𝑡|(𝑎𝑀𝑎𝑡 ⋅ 𝑏𝑀𝑎𝑡)𝑇 où |𝑐𝑀𝑎𝑡| is determining of 𝑐𝑀𝑎𝑡 (use det)

7. Operation on vector and matric.


a. Create a horizontal vector 𝑐𝑆𝑢𝑚 which each element is the sum of all elements in
each column of the matric 𝑐𝑀𝑎𝑡 (use sum)
b. Create a vertical vector 𝑐𝑀𝑒𝑎𝑛 which each element is the average of all elements in
each row of the matric 𝑒𝑀𝑎𝑡 (use mean)
c. Replace the first row of the matric 𝑒𝑀𝑎𝑡 with [1 1 1]
d. Create 𝑐𝑆𝑢𝑏, sub-matric of 𝑐𝑀𝑎𝑡, which contains rows 2 to 8 and columns 3 to 9
e. Create a horizontal vector 𝑒𝑉𝑒𝑐 with 5 elements by using rand. Find all elements
which are less than 0.5 and then change them to 0 (use find)
f. Create a vector 𝑓𝑉𝑒𝑐 = [1 2 … 20] (integers from 1 to 20) and then return
negative value for all even numbers to get 𝑓𝑉𝑒𝑐 = [1 − 2 3 − 4 … − 20]

You might also like