diff --git a/11_LU-decomposition/mass_springs.svg b/11_LU-decomposition/mass_springs.svg index 2bec8a4..c6edff5 100644 --- a/11_LU-decomposition/mass_springs.svg +++ b/11_LU-decomposition/mass_springs.svg @@ -26,15 +26,15 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="2" - inkscape:cx="7.6217341" + inkscape:cx="-97.128266" inkscape:cy="150.34609" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" units="in" - inkscape:window-width="1920" - inkscape:window-height="1019" - inkscape:window-x="0" + inkscape:window-width="2560" + inkscape:window-height="1380" + inkscape:window-x="1920" inkscape:window-y="27" inkscape:window-maximized="1" /> image/svg+xml - + @@ -59,119 +59,123 @@ d="m 25.411765,803.96215 136.588235,0" id="path8124" inkscape:connector-curvature="0" /> - - - - - - m1 m2 m3 - - + + + + + + + + + + m4 @@ -210,5 +214,61 @@ d="m 147.70523,803.80746 17.08955,-18.73167" id="path8300-8-7-2-8-2-9" inkscape:connector-curvature="0" /> + K1 + K2 + K3 + K4 diff --git a/HW4/README.html b/HW4/README.html new file mode 100644 index 0000000..468d758 --- /dev/null +++ b/HW4/README.html @@ -0,0 +1,71 @@ + + + + + + + + + + + +

Homework #4

+

due 3/28/17 by 11:59pm

+

Include all work as either an m-file script, m-file function, or example code included with ``` and document your code in the README.md file

+
    +
  1. Create a new github repository called ‘04_linear_algebra’.

    +
      +
    1. Add rcc02007 and pez16103 as collaborators.

    2. +
    3. Clone the repository to your computer.

    4. +
  2. +
  3. Create the 4x4 and 5x5 Hilbert matrix as H:

  4. +
+
    +
  1. What are the 2-norm, frobenius-norm, 0-norm and infinity-norm of the 4x4 and 5x5 Hilbert matrices?

  2. +
  3. What are the 2-norm, frobenius-norm, 0-norm and infinity-norm of the 4x4 and 5x5 inverse Hilbert matrices?

  4. +
  5. What are the condition numbers for the 2-norm, frobenius-norm, 0-norm and infinity-norm of the 4x4 and 5x5 Hilbert matrices?

  6. +
+
    +
  1. Create an LU-decomposition function called lu_tridiag.m that takes 3 vectors as inputs and calculates the LU-decomposition of a tridiagonal matrix. The output should be 3 vectors, the diagonal of the Upper matrix, and the two off-diagonal vectors of the Lower and Upper matrices.

    +

    [ud,uo,lo]=lu_tridiag(e,f,g);

  2. +
  3. Use the output from lu_tridiag.m to create a forward substitution and back-substitution function called solve_tridiag.m that provides the solution of Ax=b given the vectors from the output of [ud,uo,lo]=lu_tridiag(e,f,g). Note: do not use the backslash solver \, create an algebraic solution

    +

    x=solve_tridiag(ud,uo,lo,b);

  4. +
+
+Spring-mass system for problem 5 +

Spring-mass system for problem 5

+
+
    +
  1. Create the stiffness matrix for the 4-mass system shown above for cases a-c. Calculate the condition of the stiffness matrices. What is the expected error when calculating the displacements of the 4 masses? Include the analysis and results in your README.
  2. +
+
    +
  1. K1=K2=K3=K4=1000 N/m

  2. +
  3. K1=K3=K4=1000 N/m, K2=1000e12 N/m

  4. +
  5. K1=K3=K4=1000 N/m, K2=1000e-12 N/m

  6. +
+
    +
  1. Use lu_tridiag.m and solve_tridiag.m to solve for the displacements of hanging masses 1-4 shown above, if all masses are 1 kg.
  2. +
+
+Spring-mass system for analysis +

Spring-mass system for analysis

+
+
    +
  1. In the system shown above, determine the three differential equations for the position of masses 1, 2, and 3. Solve for the vibrational modes of the spring-mass system if k1=10 N/m, k2=k3=20 N/m, and k4=10 N/m. The masses are m1=1 kg, m2=2 kg and m3=4 kg. Create a function, mass_spring_vibrate.m that outputs the vibration modes and natural frequencies based upon the parameters, k1, k2, k3, and k4.

  2. +
  3. The curvature of a slender column subject to an axial load P can be modeled by

  4. +
+

\(\frac{d^{2}y}{dx^{2}} + p^{2} y = 0\)

+

where \(p^{2} = \frac{P}{EI}\)

+

where E = the modulus of elasticity, and I = the moment of inertia of the cross section about its neutral axis.

+

This model can be converted into an eigenvalue problem by substituting a centered finite-difference approximation for the second derivative to give \(\frac{y_{i+1} -2y_{i} + y_{i-1} }{\Delta x^{2}}+ p^{2} y_{i}\)

+

where i = a node located at a position along the rod’s interior, and \(\Delta x\) = the spacing between nodes. This equation can be expressed as \(y_{i-1} - (2 - \Delta x^{2} p^{2} )y_{i} y_{i+1} = 0\) Writing this equation for a series of interior nodes along the axis of the column yields a homogeneous system of equations. (See 13.10 for 4 interior-node example)

+

Determine the eigenvalues for a 5-segment (4-interior nodes), 6-segment (5-interior nodes), and 10-segment (9-interior nodes). Using the modulus and moment of inertia of a pole for pole-vaulting ( http://people.bath.ac.uk/taf21/sports_whole.htm) E=76E9 Pa, I=4E-8 m^4, and L= 5m.

+

Include a table in the README.md that shows the following results: What are the largest and smallest loads in the beam based upon the different shapes? How many eigenvalues are there?

+
| # of segments | largest load (N) | smallest load (N) | # of eigenvalues |
+| --- | --- | --- | --- |
+| 5 | ... | ... | ... |
+| 6 | ... | ... | ... |
+| 10 | ... | ... | ... |
+

If the segment length (\(\Delta x\)) approaches 0, how many eigenvalues would there be?

+ + diff --git a/HW4/README.md b/HW4/README.md new file mode 100644 index 0000000..a3d4a79 --- /dev/null +++ b/HW4/README.md @@ -0,0 +1,107 @@ +# Homework #4 +## due 11/2/17 by 11:59pm + +*Include all work as either an m-file script, m-file function, or example code included +with \`\`\` and document your code in the README.md file* + +1. Create a new github repository called '04_linear_algebra'. + + a. Add rcc02007 and zhs15101 as collaborators. + + b. Clone the repository to your computer. + + c. Complete this before 10/26 by midnight + +2. Create the 4x4 and 5x5 Hilbert matrix as H. Include the following results in your +README before 10/26 by midnight: + + a. What are the 2-norm, frobenius-norm, 0-norm and infinity-norm of the 4x4 and 5x5 + Hilbert matrices? + + b. What are the 2-norm, frobenius-norm, 0-norm and infinity-norm of the 4x4 and 5x5 + inverse Hilbert matrices? + + c. What are the condition numbers for the 2-norm, frobenius-norm, 0-norm and + infinity-norm of the 4x4 and 5x5 Hilbert matrices? + +3. Create an LU-decomposition function called `lu_tridiag.m` that takes 3 vectors as inputs +and calculates the LU-decomposition of a tridiagonal matrix. The output should be 3 +vectors, the diagonal of the Upper matrix, and the two off-diagonal vectors of the Lower +and Upper matrices. + + ```[ud,uo,lo]=lu_tridiag(e,f,g);``` + +4. Use the output from `lu_tridiag.m` to create a forward substitution and +back-substitution function called `solve_tridiag.m` that provides the solution of +Ax=b given the vectors from the output of [ud,uo,lo]=lu_tridiag(e,f,g). *Note: do not use +the backslash solver `\`, create an algebraic solution* + + ```x=solve_tridiag(ud,uo,lo,b);``` + +![Spring-mass system for problem 5](mass_springs.png) + +5. Create the stiffness matrix for the 4-mass system shown above +for cases a-c. Calculate the condition of the stiffness matrices. What is the expected error +when calculating the displacements of the 4 masses? Include the analysis and results in your README. + + a. K1=K2=K3=K4=1000 N/m + + b. K1=K3=K4=1000 N/m, K2=1000e12 N/m + + c. K1=K3=K4=1000 N/m, K2=1000e-12 N/m + +6. Use `lu_tridiag.m` and `solve_tridiag.m` to solve for the displacements of hanging + masses 1-4 shown above, if all masses are 1 kg. + +![Spring-mass system for analysis](spring_mass.png) + +7. In the system shown above, determine the three differential equations for the position +of masses 1, 2, and 3. Solve for the vibrational modes of the spring-mass system if k1=10 +N/m, k2=k3=20 N/m, and k4=10 N/m. The masses are m1=1 kg, m2=2 kg and m3=4 kg. Create a +function, `mass_spring_vibrate.m` that outputs the vibration modes and natural frequencies based upon the +parameters, k1, k2, k3, and k4. + +8. The curvature of a slender column subject to an axial load P can be +modeled by + + +$\frac{d^{2}y}{dx^{2}} + p^{2} y = 0$ + +![](./equations/d2ydx2.png) + +where $p^{2} = \frac{P}{EI}$ ![](./equations/p2.png) + +where E = the modulus of elasticity, and I = the moment of inertia of the cross section +about its neutral axis. + +This model can be converted into an eigenvalue problem by +substituting a centered finite-difference approximation for the second derivative to give +$\frac{y_{i+1} -2y_{i} + y_{i-1} }{\Delta x^{2}}+ p^{2} y_{i}$ + +![](./equations/delta2y.png) + +where i = a node located at a position along the rod’s interior, and $\Delta x$ = the +spacing between nodes. This equation can be expressed as $y_{i-1} - (2 - \Delta x^{2} +p^{2} )y_{i} +y_{i+1} = 0$ ![](./equations/solve.png) Writing this equation for a series of interior nodes along the +axis of the column yields a homogeneous system of equations. (See 13.10 for 4 +interior-node example) + +Determine the eigenvalues for a 5-segment (4-interior nodes), 6-segment (5-interior +nodes), and 10-segment (9-interior nodes). Using the modulus and moment of inertia of a +pole for pole-vaulting ( +[http://people.bath.ac.uk/taf21/sports_whole.htm](http://people.bath.ac.uk/taf21/sports_whole.htm)) +E=76E9 Pa, I=4E-8 m^4, and L= 5m. + +Include a table in the `README.md` that shows the following results: +What are the largest and smallest loads in the beam based upon the different shapes? How many eigenvalues are +there? + +``` +| # of segments | largest load (N) | smallest load (N) | # of eigenvalues | +| --- | --- | --- | --- | +| 5 | ... | ... | ... | +| 6 | ... | ... | ... | +| 10 | ... | ... | ... | +``` + +If the segment length approaches 0, how many eigenvalues would there be? diff --git a/HW4/README.pdf b/HW4/README.pdf new file mode 100644 index 0000000..fdb31a3 Binary files /dev/null and b/HW4/README.pdf differ diff --git a/HW4/equations/d2ydx2.png b/HW4/equations/d2ydx2.png new file mode 100644 index 0000000..5bf6b23 Binary files /dev/null and b/HW4/equations/d2ydx2.png differ diff --git a/HW4/equations/d2ydx2.tex b/HW4/equations/d2ydx2.tex new file mode 100644 index 0000000..5fa19d8 --- /dev/null +++ b/HW4/equations/d2ydx2.tex @@ -0,0 +1,2 @@ +\frac{d^{2}y}{dx^{2}} + p^{2} y = 0 + diff --git a/HW4/equations/delta2y.png b/HW4/equations/delta2y.png new file mode 100644 index 0000000..fc72c43 Binary files /dev/null and b/HW4/equations/delta2y.png differ diff --git a/HW4/equations/delta2y.tex b/HW4/equations/delta2y.tex new file mode 100644 index 0000000..a776098 --- /dev/null +++ b/HW4/equations/delta2y.tex @@ -0,0 +1,2 @@ +\frac{y_{i+1} -2y_{i} + y_{i-1} }{\Delta x^{2}}+ p^{2} y_{i} + diff --git a/HW4/equations/p2.png b/HW4/equations/p2.png new file mode 100644 index 0000000..cc2889f Binary files /dev/null and b/HW4/equations/p2.png differ diff --git a/HW4/equations/p2.tex b/HW4/equations/p2.tex new file mode 100644 index 0000000..e57ba27 --- /dev/null +++ b/HW4/equations/p2.tex @@ -0,0 +1,2 @@ +p^{2} = \frac{P}{EI} + diff --git a/HW4/equations/solve.png b/HW4/equations/solve.png new file mode 100644 index 0000000..700ae88 Binary files /dev/null and b/HW4/equations/solve.png differ diff --git a/HW4/equations/solve.tex b/HW4/equations/solve.tex new file mode 100644 index 0000000..fb7054a --- /dev/null +++ b/HW4/equations/solve.tex @@ -0,0 +1 @@ +y_{i-1} - (2 - \Delta x^{2}p^{2} )y_{i} + y_{i+1} = 0 diff --git a/HW4/figures/mass_springs.png b/HW4/figures/mass_springs.png new file mode 100644 index 0000000..770ff97 Binary files /dev/null and b/HW4/figures/mass_springs.png differ diff --git a/HW4/figures/mass_springs.svg b/HW4/figures/mass_springs.svg new file mode 100644 index 0000000..2bec8a4 --- /dev/null +++ b/HW4/figures/mass_springs.svg @@ -0,0 +1,214 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + m1 + m2 + m3 + + + m4 + + + + + + + + + diff --git a/HW4/figures/spring_mass.png b/HW4/figures/spring_mass.png new file mode 100644 index 0000000..274c049 Binary files /dev/null and b/HW4/figures/spring_mass.png differ diff --git a/HW4/figures/spring_mass.svg b/HW4/figures/spring_mass.svg new file mode 100644 index 0000000..b854162 --- /dev/null +++ b/HW4/figures/spring_mass.svg @@ -0,0 +1,299 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + x1 + x2 + x3 + + + + + m1 + m2 + m3 + k1 + k2 + k3 + k4 + + diff --git a/HW4/lu_tridiag.m b/HW4/lu_tridiag.m new file mode 100644 index 0000000..1339973 --- /dev/null +++ b/HW4/lu_tridiag.m @@ -0,0 +1,12 @@ +function [ud,uo,lo]=lu_tridiag(e,f,g);``` + % lu_tridiag calculates the components for LU-decomposition of a tridiagonal matrix + % given its off-diagonal vectors, e and g + % and diagonal vector f + % the output is + % the diagonal of the Upper matrix, ud + % the off-diagonal of the Upper matrix, uo + % and the off-diagonal of the Lower matrix, lo + % note: the diagonal of the Lower matrix is all ones + +end + diff --git a/HW4/solve_tridiag.m b/HW4/solve_tridiag.m new file mode 100644 index 0000000..0c9e510 --- /dev/null +++ b/HW4/solve_tridiag.m @@ -0,0 +1,11 @@ +function x=solve_tridiag(ud,uo,lo,b);``` + % solve_tridiag solves Ax=b for x + % given + % the diagonal of the Upper matrix, ud + % the off-diagonal of the Upper matrix, uo + % the off-diagonal of the Lower matrix, lo + % the vector b + % note: the diagonal of the Lower matrix is all ones + +end + diff --git a/HW4/test_arrays.m b/HW4/test_arrays.m new file mode 100644 index 0000000..002d79c --- /dev/null +++ b/HW4/test_arrays.m @@ -0,0 +1,8 @@ +rand("seed",1); + +for i = 3:10 + e=sort(randi(6,[i-1,1])); + f=sort(randi(10,[i,1])); + g=sort(randi(9,[i-1,1])); + eval(['A',int2str(i),'=diag(f)+diag(e,-1)+diag(g,1);']); +end diff --git a/extra_credit/README.md b/extra_credit/README.md index 2c450af..a281d57 100644 --- a/extra_credit/README.md +++ b/extra_credit/README.md @@ -4,3 +4,5 @@ Go to Mathworks [Matlab Onramp](http://bit.ly/2q97vcS) and create an account. Co Part 10 - "Review Problems" (Project - Electricity Usage) and (Project - Audio Frequency). Save your progress report and put it in a repository called 'ME3255-Extra_Credit'. + +