Professional Documents
Culture Documents
Mearg
Mearg
2/2*3
ans =
By matlab
>> 8*5/4
ans =
10
>> 8*(5/4)
ans =
10
>> 3^2/4
ans =
2.2500
It also the same result by our hand and matlab
>> 3^2^3
ans =
729
7 - 5 * 4\9
ans =
6.5500
There is a big difference between left division and right division . but the right answer by hand is -4.25
>> 6-2/5+7^2-1
ans =
53.6000
The value is the same both with math lab and hand calculated
>> 10/2\5-3+2*4
ans =
6
The value is the same both with math lab and hand calculated
>> 2+round(6/9+3*2)/2
ans =
5.5000
>> 2+floor(6/9+3*2)/2
ans =
>> 2+ceil(6/9+3*2)/2
ans =
5.5000
But the calculated value is 5.33333333
>> x=pi/3,x=x-1,x=x+5,x=abs(x)/x
x=
1.0472
x=
0.0472
x=
5.0472
x=
Number 2,
>> -3+2i+5-7i
ans =
2.0000 - 5.0000i
>> -3+2i-(5-7i)
ans =
-8.0000 + 9.0000i
>> -3+2i*(5-7i)
ans =
11.0000 +10.0000i
>> -3+2i/(5-7i)
ans =
-3.1892 + 0.1351i
Number3
>> x=[22:2:46]
x=
22 24 26 28 30 32 34 36 38 40 42 44 46
x=[4 5 9 6]
x=
4 5 9 6
>> x-3
ans =
1 2 6 3
x(1:2:end)+11
ans =
15 20
> sqrt(x)
ans =
2.0000 2.2361 3.0000 2.4495
>> x.^3
ans =
> x=[2:2:16]
x=
2 4 6 8 10 12 14 16
>> x=[9:-2:-5]
x=
9 7 5 3 1 -1 -3 -5
>> x = [2 1 3 7 9 4 6]
x=
2 1 3 7 9 4 6
>> x(3)
ans =
3
>> x(1:end)
ans =
2 1 3 7 9 4 6
>> x(1:end-1)
ans =
2 1 3 7 9 4
x(2:2:6)
ans =
1 7 4
x =[2 1 3 7 9 4 6]
x(6:-2:1)
ans =
4 7 1
Assign the number by decrement two
X=
2 1 3 7 9 4 6
>> x (end-2:-3:2)
ans =
9 1
X=
2 1 3 7 9 4 6
sum(x)
ans =
32
X=
2 1 3 7 9 4 6
mean(x)
ans =
4.5714
X=
2 1 3 7 9 4 6
min(x)
ans =
Number 4
A = [2 4 1; 6 7 2; 3 5 9]
A(1,:)
ans =
X= 2 4 1
A(2:3,:)
ans =
6 7 2
3 5 9
sum(A(:,1:3))
ans =
11 16 12
sum(A,2)
ans =
15
17
NUMBER 5
A = [2 7 9 7; 3 1 5 6; 8 1 2 5]
A'
ans =
2 3 8
7 1 1
9 5 2
7 6 5
A(1, :)'
ans =
7
9
Transpose means changing the row and column . this means column 1
A(:, [1 4])
ans =
2 7
3 6
8 5
A([23], [31])
ans =
5 3
2 8
That means column three first assign then goes to row two and three
reshape (A, 2, 6)
ans =
2 8 1 9 2 6
3 7 1 5 7 5
Reshape (A,2,6) means make the matrix two row and six column
A(:)
ans =
ans =
8 1 2 5
3 1 5 6
2 7 9 7
fliplr (A)
ans =
7 9 7 2
6 5 1 3
5 2 1 8
[A A(end, :)]
ans =
2 7 9 7
3 1 5 6
8 1 2 5
2 7 9 7
3 1 5 6
This means row one and two are also repeated to matrix A
sum (A)
ans =
13 9 16 18
ans =
25 15 16
mean (A)
ans =
mean (A')
ans =
6.2500 3.7500 4.0000
ans =
25
15
16
>>
mean (A, 2)
ans =
6.2500
3.7500
4.0000
min (A)
ans =
2 1 2 5
max (A')
ans =
9 6 8
ans =
[min(A)'max(A)']
max (min(A))
ans =
B=A(:,2:2:end)
B=
7 7
1 6
1 5
C=A(1:2:3,:)
C=
2 7 9 7
8 1 2 5
RECIPROCAL VALUE IS
D=A.^-1
D=
A'
ans =
2 3 8
7 1 1
9 5 2
7 6 5
sqrt(A)
ans =
A(:,2)=[]
A=
2 9 7
3 5 6
8 2 5
[1 1 1 1;A;1 1 1 1]
ans =
1 1 1 1
2 7 9 7
3 1 1 6
8 1 2 5
1 1 1 1
A(2,3)=A(3,2)
A=
2 9 7
3 5 2
8 2 5
Number 6
x = [1 3 7],
>> y = [2 4 2]
>> A = [3 1 6; 5 2 7]
>> B = [1 4; 7 8; 2 2],
>> x + y
ans =
3 7 9
x+A
ans =
4 4 13
6 5 14
x' + y
ans =
3 5 3
5 7 5
9 11 9
> A - [x' y']
[x; y] + A
ans =
4 4 13
7 6 9
[x; y]
ans =
1 3 7
2 4 2
A-3
ans =
0 -2 3
2 -1 4
A+B
The number of column and row should be the same for addition of two vector
B' + A
ans =
4 8 8
9 10 9
B*A
ans =
23 9 34
61 23 98
16 6 26
A.*B
2*B
ans =
2 8
14 16
4 4
2. *B
ans =
2 8
14 16
4 4
If we multiply scalar with number it is equal by using the dot in the multiplication
B./x'
ans =
1.0000 4.0000
2.3333 2.6667
0.2857 0.2857
B./[x' x']
ans =
1.0000 4.0000
2.3333 2.6667
0.2857 0.2857
2/A
Error using /
Scalar number cannot be divided by vector because scalar vector have 1by 1 dimension
ones(1,3)* A
ones(1, 3) * B
ans =
10 14
Number 7
A=rand(5,5)
A=
>> B=rand(5,1)
B=
0.6663
0.5391
0.6981
0.6665
0.1781
>> X=B/A
Error using /
>> X=B\A
X=
inv(A)
ans =
>> X=inv(A)*B
X=
5.4155
2.7556
3.2721
-8.8465
-1.9261
>> A*X-B
ans =
1.0e-14 *
-0.0111
-0.0111
-0.0111
-0.0333
-0.1277
>>
Number 8
A=[3 4;6 8]
A=
3 4
6 8
B=
6 8
9 10
>> A.*B
ans =
18 32
54 80
>> A*B
ans =
54 64
108 128
A/B
ans =
0.5000 -0.0000
1.0000 -0.0000
A\B
ans =
-Inf -Inf
Inf Inf
NUMBER 9
A = [1:4; 5:8; 1 1 1 1]
A=
1 2 3 4
5 6 7 8
1 1 1 1
>> x = A(:, 3)
x=
B = A(1 : 3, 2 : 2)
B=
A(1, 1) = 9 + A(2, 3)
A=
16 2 3 4
5 6 7 8
1 1 1 1
A = [1:4; 5:8; 1 1 1 1]
A=
1 2 3 4
5 6 7 8
1 1 1 1
>> A(2 : 3, 1 : 3) = [0 0 0; 0 0 0]
A=
1 2 3 4
0 0 0 8
0 0 0 1
A = [1:4; 5:8; 1 1 1 1]
A=
1 2 3 4
5 6 7 8
1 1 1 1
>> A(2 : 3, 1 : 2) = [1 1; 3 3]
A=
1 2 3 4
1 1 7 8
3 3 1 1
A=[1:4; 5:8; 1 1 1 1]
A=
1 2 3 4
5 6 7 8
1 1 1 1
>> x = A(:, 3)
x=
y = A(3 : 3, 1 : 4)
y=
1 1 1 1
A = [A; 2 1 7 7; 7 7 4 5]
A=
1 2 3 4
5 6 7 8
1 1 1 1
2 1 7 7
7 7 4 5
• C = A([1, 3], 2)
C=
D=
5 7 8
1 1 1
7 4 5
D(2, :) = [ ]
D=
5 7 8
7 4 5
y = A(3 : 3, 1 : 4)
y=
1 1 1 1
NUMBER 10
A=rand(6,6)
A=
ans =
0.2399 0 0 0 0 0
0 0.5005 0 0 0 0
0 0 0.0967 0 0 0
0 0 0 0.9730 0 0
0 0 0 0 0.1332 0
0 0 0 0 0 0.5269
>> B=A-ans+eye(6,6)
B=
>> triu(A)
ans =
0.2399 0.7127 0.0714 0.1499 0.4538 0.3909
0 0 0 0 0.1332 0.3993
0 0 0 0 0 0.5269
>> triu(A,1)
ans =
0 0 0 0 0.0835 0.0605
0 0 0 0 0 0.3993
0 0 0 0 0 0
>> triu(A,2)
ans =
0 0 0 0 0 0.0605
0 0 0 0 0 0
0 0 0 0 0 0
>> z= triu(A,1)-triu(A,2)
z=
0 0.7127 0 0 0 0
0 0 0.5216 0 0 0
0 0 0 0.5186 0 0
0 0 0 0 0.0835 0
0 0 0 0 0 0.3993
0 0 0 0 0 0
>> tril(A,-1)
ans =
0 0 0 0 0 0
0.8865 0 0 0 0 0
0.0287 0.4711 0 0 0 0
>> tril(A,-2)
ans =
0 0 0 0 0 0
0 0 0 0 0 0
0.0287 0 0 0 0 0
0.4899 0.0596 0 0 0 0
>> k = tril(A,-1)-tril(A,-2)
k=
0 0 0 0 0 0
0.8865 0 0 0 0 0
0 0.4711 0 0 0 0
0 0 0.8181 0 0 0
0 0 0 0.6490 0 0
0 0 0 0 0.1734 0
>> T = z+k+diag(diag(A))
T=
0.2399 0.7127 0 0 0 0
0 0 0 0 0.1734 0.5269
>>