## A matrix is symmetric if A=A'¶

### Diagonal matrices are symmetric¶

In [4]:
D=diagm(1:5);
(D,D')

Out[4]:
(
5x5 Array{Int64,2}:
1  0  0  0  0
0  2  0  0  0
0  0  3  0  0
0  0  0  4  0
0  0  0  0  5,

5x5 Array{Int64,2}:
1  0  0  0  0
0  2  0  0  0
0  0  3  0  0
0  0  0  4  0
0  0  0  0  5)

In [9]:
issym(D)

Out[9]:
true


### If S is symmetric, inv(S) ' = inv(S') = inv(S) hence inv(S) is symmetric¶

In [5]:
S=[3 12;12 5]

Out[5]:
2x2 Array{Int64,2}:
3  12
12   5

In [8]:
round(inv(S),7)

Out[8]:
2x2 Array{Float64,2}:
-0.0387597   0.0930233
0.0930233  -0.0232558


### If R is any rectangular matrix R'*R is symmetric: Why?¶

In [12]:
R=rand(5,2); round(R*R',3)

Out[12]:
5x5 Array{Float64,2}:
0.871  1.166  0.816  0.085  0.987
1.166  1.598  1.004  0.113  1.35
0.816  1.004  0.972  0.081  0.856
0.085  0.113  0.081  0.008  0.096
0.987  1.35   0.856  0.096  1.14

In [11]:
issym(R*R')

Out[11]:
true

In [13]:
a=R'*R

Out[13]:
2x2 Array{Float64,2}:
1.7064   1.93981
1.93981  2.88402

In []:
Fact without proof: if S is symmetric, elimination produces S=LDL'


## Permutation Matrices¶

In [21]:
A=randn(5,5);
(L,U,P)=lu(A);
(round(L,3),round(U,3),round(P,1))

Out[21]:
(
5x5 Array{Float64,2}:
1.0     0.0     0.0     0.0    0.0
0.835   1.0     0.0     0.0    0.0
0.607   0.411   1.0     0.0    0.0
-0.885   0.216  -0.248   1.0    0.0
-0.519  -0.577  -0.639  -0.984  1.0,

5x5 Array{Float64,2}:
-0.831  -1.29    0.041   0.83    2.648
0.0     2.539   1.151  -0.157  -4.152
0.0     0.0    -1.898  -1.537   0.432
0.0     0.0     0.0     0.841   4.13
0.0     0.0     0.0     0.0     1.541,

5x5 Array{Float64,2}:
0.0  1.0  0.0  0.0  0.0
0.0  0.0  1.0  0.0  0.0
0.0  0.0  0.0  0.0  1.0
1.0  0.0  0.0  0.0  0.0
0.0  0.0  0.0  1.0  0.0)

In [22]:
(round(P*A,3),round(L*U,3))

Out[22]:
(
5x5 Array{Float64,2}:
-0.831  -1.29    0.041   0.83    2.648
-0.694   1.461   1.186   0.537  -1.941
-0.505   0.261  -1.4    -1.097   0.332
0.736   1.689   0.682   0.453   0.784
0.431  -0.794   0.527  -0.186  -1.78 ,

5x5 Array{Float64,2}:
-0.831  -1.29    0.041   0.83    2.648
-0.694   1.461   1.186   0.537  -1.941
-0.505   0.261  -1.4    -1.097   0.332
0.736   1.689   0.682   0.453   0.784
0.431  -0.794   0.527  -0.186  -1.78 )


## A real vector space is a set of "vectors" with an addition and multiplication by scalars that satisfies eight rules (rules coming soon)¶

#### vectors in standard format¶

In [27]:
v=rand(0:9, 5);  w=rand(0:9,5); [v w]

Out[27]:
5x2 Array{Int64,2}:
4  0
6  3
8  9
3  8
8  3

In [28]:
v*10

Out[28]:
5-element Array{Int64,1}:
40
60
80
30
80

In [29]:
v+w

Out[29]:
5-element Array{Int64,1}:
4
9
17
11
11


#### arrays themselves are vectors¶

In [31]:
A=rand(0:9,2,2); B=rand(0:9,2,2); (A,B)

Out[31]:
(
2x2 Array{Int64,2}:
3  3
9  5,

2x2 Array{Int64,2}:
2  9
7  7)

In [32]:
A*10

Out[32]:
2x2 Array{Int64,2}:
30  30
90  50

In [33]:
A+B

Out[33]:
2x2 Array{Int64,2}:
5  12
16  12


### functions are vectors¶

In [35]:
typeof(sin)

Out[35]:
Function

In [36]:
sin+cos

no method +(Function,Function)
at In[36]:1
In [37]:
+(f::Function,g::Function)=x->f(x)+g(x);

In [38]:
(sin+cos)(12)

Out[38]:
0.3072810407320572

In [39]:
sin(12)+cos(12)

Out[39]:
0.3072810407320572

In [39]:
*(c::Number,f::Function) = x->c*f(x);

In [40]:
(10*sin)(5)

Out[40]:
-9.589242746631385

In [41]:
10*sin(5)

Out[41]:
-9.589242746631385

In [44]:
x=-10:.001:10; plot(x, (sin+cos)(x));

In [47]:
plot( x, (10cos)(x));

1. x+y = y+x COMMUTATIVE LAW OF ADDITION 2. x+ (y+z) = (x+y)+z ASSOCIATIVE LAW OF ADDITION 3. There is a unique "zero vector" such that x+0 = x ADDITIVE IDENTIY 4. For each x there is a -x such that x + (-x) = 0 ADDITIVE INVERSES 5. 1 * x = x MULTIPLICATIVE IDENTITY 6. (c1*c2)x=c1*(c2*x) ASSOCIATIVE LAW OF SCALAR,SCALAR,VECTOR MULTIPLICATIONS 7. c(x+y)-cx+cy MULTIPLICATION DISTRIBUTES OVER VECTOR ADDITION 8. (c1+c2)x = c1 x + c2 x SCALAR ADDITION DISTRIBUTES OVER MULTIPLICATION
In []:
Subspaces: Are sums in the space?  Are constant times vector in the space?