Professional Documents
Culture Documents
P Matlab
P Matlab
Excercise 2:
MAT=[356, 127, 96;
270, 500, 489;
451, 123, 321]
MAT = 3×3
356 127 96
270 500 489
451 123 321
Excercise 3:
last_row=[0,0,1]*MAT
last_row = 1×3
451 123 321
Excercise 4:
v1=[1,2,3,4,5]
v1 = 1×5
1 2 3 4 5
v2=[1,1,1]'
v2 = 3×1
1
1
1
B=v2*v1
B = 3×5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Excercise 5:
a) FORTRAN
b) MAT(3,2) =123
MAT(3,2)
ans = 123
1
d)
Colon operator (:) - The colon operator generates a vector of equally spaced elements between two given
values. For example, 1:5 creates a vector [1 2 3 4 5], and 0:0.1:1 creates a vector [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
0.8 0.9 1.0].
Logical operator (& and |) - The logical operators are used to perform logical operations on arrays or matrices.
The "&" operator returns a logical value of 1 (true) if both operands are non-zero, otherwise, it returns 0 (false).
The "|" operator returns a logical value of 1 (true) if either operand is non-zero, otherwise, it returns 0 (false).
Assignment operator (=) - The assignment operator is used to assign a value to a variable. For example, x = 5
assigns the value 5 to the variable x.