Beruflich Dokumente
Kultur Dokumente
LAB #1
Brief review of MATLAB instructions known from previous courses
MATLAB use:
A+B sum
A-B difference
A*B scalar product
A.*B product (element by element)
A./B ratio (element by element)
A^2 A*A (scalar product)
A.^2 square (element by element)
max(A) o min(A) MATLAB builds a vector containing the maximum (or
minimum) element of each column.
abs(A) absolute value of (A).
sum(A,p) creates a row vector whose elements are sum BY COLUMN of the
elements of A (if p=1) or a column vector whose elements are the sum BY ROW of
the elements of A (if p=2)
plot(x,y,type_of_line or type_of_point)
disp(print_this_sentence_on_the_screen);
load filename.dat or load filename.mat
save filename [variable1, variable2, ]
sin(x)
cos(x)
exp(x)
log(x) natural logarithm
CM Lab #1
Oct. 4, 2013
CM Lab #1
Oct. 4, 2013
EXERCISES
1) Assign the variables A=20 and B=5
a. Compute the sum S and the product P of A and B.
b. Compute A^2.
c. Change the value of A to 10 and check the values of A and B in the workspace.
d. Clear the sum S and recomputed it with the new values.
e. Recompute also the product P without clearing it before.
f. Try to assign the variable named 3A=24: what happens?
g. Clear the command prompt.
h. Save the sum and the product in a file named ES1_yoursurname_
BaseOperations.properextension. Try with both .mat and .dat files.
i. Create the folder Lab1 in d:\ and save the same file in that folder.
j. Define the variable a=8 and check the value of variable A.
k. Clear all the variables.
l. Load the file and check the variables values.
3];
B=[3 6
4];
CM Lab #1
Oct. 4, 2013
4) Using the special matrices ones, zeros and eye, assign the matrix:
A=[0
0
1
1
1
2
2
2
0
0
1
1
1
4
4
4
1
2
3
0
0
0
2
0
2
1
2
0
0
0
0
2
3
2
1
0
0
0
0
0
1
0
0
3
3
6
7
0
0
1
0
3
3
6
0
7
0
0
1
3
3
6
0
0]
Q=[1
2
3
4
1
9
6
8
4
2
3
4
6
3
7
8
1
6
3
4
5
8
5
5
2
3
4
4
5
6
1
7
3
9
5
6
5
6
7
3
9
1
7
7
4
6
7
8
5
2
8
5
9
8
7
8
9
7
4
6
3
2
6
8
9
1
9
6
4
1
4
8
And then:
a) Compute the sum of the terms in the odd columns.
b) Compute the sum of the terms in the main diagonal.
c) Compute the sum of the outermost frame elements, which are not 4.
d) Compute the sum of all the matrix terms, excluding those equal to 9, close to 7.
6) We want to plot the function y=sin(x) with 0x50, using the MATLAB pre-defined
function sin(x).
a) Assign a vector x containing all the points from 0 e 50, with increment 0.01, and
compute the y vector with an array-smart command.
b) Plot y as a function of x.
CM Lab #1
Oct. 4, 2013