Skip to content

ere13004/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
March 29, 2017 00:01
March 28, 2017 17:26
add
March 28, 2017 23:41
March 28, 2017 17:29
March 28, 2017 23:58

linear_algebra HW5

2.

function [ud,uo,lo]=lu_tridiag(e,f,g);
%lu_tridiag The purpose of this function is to perform a LU-decomposition
%by creating a lower and upper matrix from three input vectors e,f,&g. This
%function is to provide a method that creates linear equations to compute
%the new matrix.
%Note: the inputs of the function must be vectors of the same length
%--------Linear equations-----------
ud = zeros(length(f), 1); %set up empty vector for new upper diagonal
uo = zeros(length(f)-1, 1); %empty vector for new upper-off diagonal matrix
lo = zeros(length(f)-1, 1); %empty vector for new lower-off diagonal matrix

lo = g;       %The value of the original upper matrix equals the new lower-off diagonal
ud(1)=f(1);   %first element in new upper diagonal equals first in original diagonal 
uo(1) = g(1); %first element in new upper-off diagonal equals that of first in g
k = 2;        %Set index to initialize while loop.

while k <= length(f)-1 %begin loop to assign values of generic vectors e f &g
    lo(k-1) = e(k-1)/(ud(k-1)); %compute values for new lower-off digaonal
    uo(k) = g(k); %assign values to new upper-off diagonal
    ud(k) = f(k)-(lo(k-1)*uo(k-1));
    k = k + 1; %repeat but shift to next column
end
lo(k-1) = e(k-1)/(ud(k-1)); %Due to indexing loop, equation is needed for final value of new lower-off diagonal
 ud(k) = f(k)-(lo(k-1)*uo(k-1)); %same reasoning, needed to find final value of new upper diagonal
 


3.

function x=solve_tridiag(ud,uo,lo,b);
%solve_tridiag The purpose of this function is to solve common equation
%Ax=b given the diagonal of the upper matrix(ud), and the off diagonals
%(uo,lo) and the vector b. The procedure similar to Cholesky factorization.

n = length(b); %set dimension of n based on input vector
x = zeros(n,1); %create an empty vector to store values of length n
y = zeros(n,1); % create an empty vector to store values of length n that will be manipulated
y(1) = b(1); %Assign the first y value to equal the first value of vector b (equal to one)

%Set up iterative procedure to back solve for the vectors of the off
%diagonals. (similar to Cholesky's step procedure).
for i=2:n %for loop beginning with second element 
    y(i)=b(i)-lo(i-1)*y(i-1); %utilize the first given input to calculate the first value of the lower off diagonal
    
end

x(n) = y(n)/ud(n); 
for i=n-1:1 %procedure to algebraically find the values  of the upper diagonal
    x(i)=(y(i)-uo(i)*x(i+1))/ud(i);
end
          

4.

size of A norm(error)
3 1.0424
4 1.0541
5 1.2655
6 N/A
7 1.3289
8 1.0558
9 1.2290
10 N/A

Note: N/A errors hypothesized from an imaginary eigen or dividing by zero

5.

Natrual Frequency 1 = 2sqrt(5)

Natural Frequency 2 = 0.5(sqrt(5*(sqrt(129)-9)))

Note: In order to calculate the natural frequencies, the first matrix was simplified into a polynomial of degree 8. The poly() function was utilized poly(80 0 20 0 -4200 0 12000) to isolate the roots. The eig() function was utilized for the second, simplified matrix in order to isolate the eigenvalues for each natural frequency.

![first work] (first work.png) ![second work] (second work.png)

6.

# of segments largest smallest # of eigenvalues
5 3.6180 0.3820 4
6 3.7321 0.2679 5
10 3.9021 0.0979 9
10000 4 9.8696e-8 9999

If the segment length (dx) approaches 0, this implies that the number of segments continues to grow to infinity. Therefore, there will also be an infinite number of eigenvalues. This conclusion is supported by the pattern in behavior illustrated in the table above.

Script for 6
function [ max_eig,min_eig,quant_eig] = PoleVault( segments,length )
%PoleVault The purpose of the function is to find the eigenvalues for a
%slender column subject in axial load for a general number of segments.
%   This function employs a finite difference approximation in order to
%   find eigenvalues that would satisfy the equation for a series of
%   interior nodes along the axis of the column. Suppressed at the bottom
%   is script to calculate the load P on the pole

matrix = zeros(segments-1); %create empty matrix dependent on the # of internal nodes

%-------- Matrix ----------------------------------------- 
% Create method to create matrix for any number of segments
for i=1:segments-1 %for loop to assign value to each matrix element
    matrix(i,i) = 2; %Assigns values of two to the diagonal of the matrix
    if (i ~= 1) %condition for neighboring column
        matrix(i,i-1) = -1; %Assigns value for each diagonal directly below the center diagonal
    end
    if (i~=segments-1)
        matrix(i,i+1) = -1; %Assigns value for each diagonal element directly above the center diagonal
    end
end     
%--------- Calculations ----------------------------------
values = eig(matrix);   %vector that possesses eigen values of 'matrix'
quant_eig = numel(values); %Sum the quantity of eigenvalues 
max_eig = max(values);  %Identify the maximum of the eigenvalues
min_eig = min(values);  %Identify the minimum of the eigenvalues

%---------- Calculation of Load, P ----------------------------------
%dx = length/segments;   %calculate the change in length between segments
%E = 76000000000; %Pole's modulus of elasticity
%I = 4*10^(-8); %Moment of inertia of pole
%radius = sqrt(values./(dx^2)) %radius of pole
%load = (E*I)*(radius.^2) %load calculation
end

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Languages