# 04_linear_algebra

HW4 ME3255 #Problem 2 #Part A Outputs of taking norms of matrices

4x4: (2 norm = 1.5002) (frobenius-norm = 1.5097) (1 norm = 2.0833) (infinity-norm = 2.0833)

5x5: (2 norm = 1.5671) (frobenius-norm = 1.5809) (1-norm = 2.2833) (infinity-norm = 2.2833)

#Part B Outputs of taking norms of inverse Hilbert matrices

4x4: (2 norm = 1.0341e+04) (frobenius-norm = 1.0342e+04) (1 norm = 13620) (infinity-norm = 13620)

5x5: (2 norm = 3.0414e+05) (frobenius-norm = 3.0416e+05) (1 norm = 413280) (infinity-norm = 413280)

#Part C Outputs of condition numbers on 4x4 and 5x5 Hilbert matrices

4x4: (2-norm = 1.5514e+04) (frobenius-norm = 1.5614e+04) (1 norm = 2.8375e+04) (infinity-norm = 2.8375e+04)

5x5: (2 norm = 4.7661e+05) (frobenius-norm = 4.8085e+05) (1 norm = 9.4366e+05) (infinity-norm = 9.4366e+05)

#Problem 3 and 4

```
function [d,u]=chol_tridiag(e,f);
% chol_tridiag is a function that takes 2 vectors as inputs and calculates
%the Cholseky factorization of a tridiagonal matrix
% given e, the off-diagonal vector
% and f, the diagonal vector
% output = [d,u]
% d is the diagonal of the Upper matrix
% u isthe off-diagonal of the Upper matrix
d = zeros(length(f),1);
u = zeros(length(f)-1,1);
d(1) = sqrt(f(1));
u(1) = e(1)/d(1);
l = 2;
while l <= length(f)-1
d(l) = sqrt(f(l)- (u(l-1))^2);
u(l) = e(l)/d(l);
l = l+1;
end
d(4) = sqrt(f(4)-(u(3))^2);
end
```

```
function [x] = solve_tridiag(u,d,b)
% provides solution of Ax=b
% d = diagonal of upper matrix of cholesky factorization
% u = off-diagonal of upper matrix of cholesky factorization
% b = the vector
x = zeros(1,length(b));
y = zeros(1,length(b));
y(1) = b(1)/d(1);
for i=2:length(b)
y(i)=(b(i)-u(i-1)*y(i-1))/d(i);
end
x(length(b)) = y(length(b))/d(length(b));
for i = n-1:-1:1
x(i) = ((y(i)-u(i))*x(i+1))/d(i);
end
end
```

#Problem 5 for k = 1000, x = 29.28 and error = 29.28

for k2 = 1000e12 x = (2.9e10) and error = 1.13e12

for k2 = 1000e-12 x = (3e-10) and error = 9.001e12

#Problem 6 x = [0.039, 0.069, 0.083, 0.098]

#Problem 7 answer that I got was =[40.522, 14.409, 2.569]

#Problem 8

number of segments | Largest Load | Smallest Load | num of eigenvalues |
---|---|---|---|

5 | 1.1756 | 0.6180 | 2 |

6 | 1.2 | 0.6212 | 3 |

10 | 1.2361 | 0.6257 | 7 |

When the segment length approaches 0, the number of eigenvalues also approaches zero.