Skip to content

cpl11001/04_linear_algebra

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
HW4
 
 
 
 
 
 
 
 

04_linear_algebra

Linear Algebra HW 4

Problem 2

Part A

H4 = [1,1/2,1/3,1/4;1/2,1/3,1/4,1/5;1/3,1/4,1/5,1/6;1/4,1/5,1/6,1/7];
norm(H4,2)
norm(H4,'fro')
norm(H4,1)
norm(H4,inf)

H5 = [1,1/2,1/3,1/4,1/5;1/2,1/3,1/4,1/5,1/6;1/3,1/4,1/5,1/6,1/7;1/4,1/5,1/6,1/7,1/8;1/5,1/6,1/7,1/8,1/9]
norm(H5,2)
norm(H5,'fro')
norm(H5,1)
norm(H5,inf)

Output (4x4):

  • 2-norm: 1.5002
  • frobenius-norm: 1.5097
  • 1-norm: 2.0833
  • inf-norm: 2.0833

Output (5x5):

  • 2-norm: 1.5671
  • frobenius-norm: 1.5809
  • 1-norm: 2.2833
  • inf-norm: 2.2833

Part B

H4 = [1,1/2,1/3,1/4;1/2,1/3,1/4,1/5;1/3,1/4,1/5,1/6;1/4,1/5,1/6,1/7];
iH4 = inv(H4)
norm(iH4,2)
norm(iH4,'fro')
norm(iH4,1)
norm(iH4,inf)

H5 = [1,1/2,1/3,1/4,1/5;1/2,1/3,1/4,1/5,1/6;1/3,1/4,1/5,1/6,1/7;1/4,1/5,1/6,1/7,1/8;1/5,1/6,1/7,1/8,1/9];
iH5 = inv(H5)
norm(iH5,2)
norm(iH5,'fro')
norm(iH5,1)
norm(iH5,inf)

Output (4x4):

  • 2-norm: 1.0341e+04
  • frobenius-norm: 1.0342e+04
  • 1-norm: 1.3620e+04
  • inf-norm: 1.3620e+04

Output (5x5):

  • 2-norm: 3.0414e+05
  • frobenius-norm: 3.0416e+05
  • 1-norm: 4.1328e+05
  • inf-norm: 4.1328e+05

Part C

H4 = [1,1/2,1/3,1/4;1/2,1/3,1/4,1/5;1/3,1/4,1/5,1/6;1/4,1/5,1/6,1/7];
cond(H4,2)
cond(H4,'fro')
cond(H4,1)
cond(H4,inf)

H5 = [1,1/2,1/3,1/4,1/5;1/2,1/3,1/4,1/5,1/6;1/3,1/4,1/5,1/6,1/7;1/4,1/5,1/6,1/7,1/8;1/5,1/6,1/7,1/8,1/9];
cond(H5,2)
cond(H5,'fro')
cond(H5,1)
cond(H5,inf)

Output (4x4):

  • 2-norm: 1.5514e+04
  • frobenius-norm: 1.5614e+04
  • 1-norm: 2.8375e+04
  • inf-norm: 2.8375e+04

Output (5x5):

  • 2-norm: 4.7661e+05
  • frobenius-norm: 4.8085e+05
  • 1-norm: 9.4366e+05
  • inf-norm: 9.4366e+05

Problem 3

function [d,u]=chol_tridiag(e,f);
  % chol_tridiag calculates the components for Cholesky factorization of a symmetric
  % positive definite tridiagonal matrix
  % given its off-diagonal vector, e  
  % and diagonal vector f
  % the output is
  % the diagonal of the Upper matrix, d
  % the off-diagonal of the Upper matrix, u

 d = zeros(length(f),1);
 u = zeros(length(f)-1,1);

 d(1) = sqrt(f(1));
 u(1) = e(1)/d(1);

 k = 2;

 while k <= length(f)-1
     d(k) = sqrt(f(k)- (u(k-1))^2);
     u(k) = e(k)/d(k);
     k = k+1;
 end

 d(4) = sqrt(f(4)-(u(3))^2);

end

Problem 4

function [x] = solve_tridiag(u,d,b)
  % Function that provides the solution of Ax=b
  % given:
  % diagonal of upper matrix of cholesky factorization, d
  % off-diagonal of upper matrix of cholesky factorization, u
  % the vector, b

  x = zeros(1,length(b));
  y = zeros(1,length(b));
  % forward substitution
  y(1) = b(1)/d(1);

  for i=2:length(b)
      y(i)=(b(i)-u(i-1)*y(i-1))/d(i);
  end
  % back substitution
  x(length(b)) = y(length(b))/d(length(b));
  for i = length(b)-1:-1:1
      x(i) = ((y(i)-u(i))*x(i+1))/d(i);
  end
end

Problem 5

Part A

k = 1000;
k1 = k;
k2 = k1;
k3 = k2;
k4 = k3;
K = [2*k,-k,0,0;-k,2*k,-k,0;0,-k,2*k,-k;0,0,-k,k];
x = cond(K)
c = log10(x);
t_k = 0; % accuracy of coefficients of K: 10^-t (accuracy is 1 so t = 0)
e = 10^(c-t_k)

Condition:

  • 29.2841

Error:

  • 29.2841

Part B

k = 1000;
k1 = k;
k2 = 1000*10^12;
k3 = k1;
k4 = k3;
K = [k1+k2,-k2,0,0;-k2,k2+k3,-k3,0;0,-k3,k3+k4,-k4;0,0,-k4,k4];
x = cond(K)
c = log10(x);
t_k = 9; % accuracy of coefficients of K: 10^-t
e = 10^(c-t_k)

Condition:

  • 1.1291e13

Error:

  • 1.1291e22

Part C

k = 1000;
k1 = k;
k2 = 1000*10^-12;
k3 = k1;
k4 = k3;
K = [k1+k2,-k2,0,0;-k2,k2+k3,-k3,0;0,-k3,k3+k4,-k4;0,0,-k4,k4];
x = cond(K)
c = log10(x);
t_k = 9; % accuracy of coefficients of K: 10^-t
e = 10^(c-t_k)

Condition:

  • 9.001e12

Error:

  • 9.001e3

Problem 6

Part A

k = 1000;
k1 = k;
k2 = k1;
k3 = k2;
k4 = k3;
e = [-k2,-k3,-k4];
f = [k1+k2,k2+k3,k3+k4,k4];
[d,u] = chol_tridiag(e,f)
b = [1;1;1;1];
[x] = solve_tridiag(u,d,b)

Displacements:

  • mass 1: 0.0025 m
  • mass 2: 0.0050 m
  • mass 3: 0.0075 m
  • mass 4: 0.0100 m

Part B

k = 1000;
k1 = k;
k2 = 1000e12;
k3 = k1;
k4 = k3;
e = [-k2,-k3,-k4];
f = [k1+k2,k2+k3,k3+k4,k4];
[d,u] = chol_tridiag(e,f)
b = [1;1;1;1];
[x] = solve_tridiag(u,d,b)

Displacements:

  • mass 1: 0.0023 m
  • mass 2: 0.0023 m
  • mass 3: 0.0047 m
  • mass 4: 0.0070 m

Part C

k = 1000;
k1 = k;
k2 = 1000e-12;
k3 = k1;
k4 = k3;
e = [-k2,-k3,-k4];
f = [k1+k2,k2+k3,k3+k4,k4];
[d,u] = chol_tridiag(e,f)
b = [1;1;1;1];
[x] = solve_tridiag(u,d,b)

Displacements:

  • mass 1: 3008695.77 m
  • mass 2: 3008695769.04 m
  • mass 3: 3005690078.97 m
  • mass 4: 2999690697.57 m

Problem 7

function  [v,w] = mass_spring_vibrate(k1,k2,k3,k4)
    % Function that finds the vibration modes (v) and natural frequencies (w) of a
    % spring - mass system given four parameters k1,k2,k3,k4
    m1 = 1; %kg
    m2 = 2;%kg
    m3 = 4; %kg
    % x1 = A1*sin(w*t);
    % x2 = A2*sin(w*t);
    % x3 = A3*sin(w*t);
    %((k2+k1)/m1-w^2)*x1 - (k2/m1)*x2 = 0; differential equation 1
    %((k2+k3)/m2)*x2 - (k2/m2)*x1 - (k3/m2)*x3 = 0; differential equation 2
    %((k3+k4)/m3)*x3 - (k4/m3)*x2 = 0; differential equation 3
    K = [(k2+k1)/m1, -k2/m1, 0; -k2/m2,(k2+k3)/m2, -k3/m2; 0, -k4/m3, (k2+k1)/m3];
    [v,lambda] = eig(K);
    w = sqrt(lambda);
end

Outputs:

  • Mode 1: Natural Frequency = 6.345 rad/sec
    • Mass 1 and 3 in phase with each other, mass 2 out of phase
  • Mode 2: Natural Frequency = 3.594 rad/sec
    • Mass 1 and 2 in phase with each other, mass 3 out of phase
  • Mode 3: Natural Frequency = 2.08 rad/sec
    • Mass 1,2 and 3 in phase with each other

Problem 8

# of segments largest load (N) smallest load (N) # of eigenvalues
5 10998.82 1161.18 4
6 16337.43 1172.97 5
10 47449.69 1190.31 9

As the number of segments approaches zero, the eigenvalues will decrease until there is only one

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published