format compact
more off
b = [3;
2;
9]
b =
3
2
9
b=[3;2;9]
b =
3
2
9
A=[1 2 3; 0 5 6; 7 8 9]
A =
1 2 3
0 5 6
7 8 9
% Do NOT do this
badBadDet=det(A)
badBadDet =
-24
x=inv(A)*b
x =
1.0000
-2.0000
2.0000
cond(A)
ans =
37.9389
x=A\b
x =
1
-2
2
A(2,1)
ans =
0
A(2,1)=4
A =
1 2 3
4 5 6
7 8 9
cond(A)
ans =
1.2011e+17
x=A\b
[Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND
= 1.541976e-18.]
[]
x =
1.0e+16 *
-3.6029
7.2058
-3.6029
% matrix manipulations
A(2,1)=0
A =
1 2 3
0 5 6
7 8 9
x=A\b
x =
1
-2
2
% transpose changes rows intio columns and vice-versa
x'
ans =
1 -2 2
xT=x'
xT =
1 -2 2
xT'
ans =
1
-2
2
A
A =
1 2 3
0 5 6
7 8 9
AT=A'
AT =
1 0 7
2 5 8
3 6 9
% more
Ax=A*x
Ax =
3
2
9
errorAX=A*x-b
errorAX =
0
0
0
A(2,1)=4
A =
1 2 3
4 5 6
7 8 9
x=A\b
[Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND
= 1.541976e-18.]
[]
x =
1.0e+16 *
-3.6029
7.2058
-3.6029
A*x
ans =
0
0
0
A(2,1)=0
A =
1 2 3
0 5 6
7 8 9
x=A\b
x =
1
-2
2
A
A =
1 2 3
0 5 6
7 8 9
B=[x b x x]
B =
1 3 1 1
-2 2 -2 -2
2 9 2 2
B*A
{Error using *
Inner matrix dimensions must agree.}
A*B
ans =
3 34 3 3
2 64 2 2
9 118 9 9
AStarB=A*B
AStarB =
3 34 3 3
2 64 2 2
9 118 9 9
x
x =
1
-2
2
lengthxsquared=x'*x
lengthxsquared =
9
x'
ans =
1 -2 2
x
x =
1
-2
2
x
x =
1
-2
2
x'
ans =
1 -2 2
x*x'
ans =
1 -2 2
-2 4 -4
2 -4 4
x*x
{Error using *
Inner matrix dimensions must agree.}
x^2
{Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.}
A
A =
1 2 3
0 5 6
7 8 9
x
x =
1
-2
2
xPtStarx=x.*x
xPtStarx =
1
4
4
x.^2
ans =
1
4
4
A
A =
1 2 3
0 5 6
7 8 9
size(A)
ans =
3 3
A*A
ans =
22 36 42
42 73 84
70 126 150
AStarA=A*A
AStarA =
22 36 42
42 73 84
70 126 150
A
A =
1 2 3
0 5 6
7 8 9
APtStarA=A.*A
APtStarA =
1 4 9
0 25 36
49 64 81
AStarA=A*A
AStarA =
22 36 42
42 73 84
70 126 150
A^2
ans =
22 36 42
42 73 84
70 126 150
APtStarA=A.*A
APtStarA =
1 4 9
0 25 36
49 64 81
APtStarA=A.^2
APtStarA =
1 4 9
0 25 36
49 64 81
exit