You are on page 1of 12

Analysis of a Spring-Mass System at Equilibrium:

In C++ Code

Devyn Kirban

February 26, 2018

Abstract

In many engineering-related problems, we encounter vertical spring-mass systems. These systems

can have various components within them such as multiple springs attached to one mass and

multiple spring-mass systems attached to each other. In this paper, we will observe the forces

applied to a combination of spring-mass systems, form a stiffness matrix, find the inverse matrix,

and solve for displacements if under certain parameters using C++ coding.

Introduction

Fig.1: A system composed of three masses suspended vertically by a series of springs.

(a) The system before release. (b) The system after release.
Fig.1 shows an arrangement of three masses and four springs where after being released is purely

pulled downward by the force of gravity. In order to solve this problem for the unknown

displacements, we use an understanding of physics to develop equations and then use LU

decomposition with Gauss elimination using dynamic memory in C++ to solve them. We found

that with m1= 10 Kg, m2= 20 Kg, m3= 30 Kg, g= 10 m/s2 and k= 10 Kg/s2, the displacements

were 60m, 85m, and 115m. We then found the same values for the displacements by multiplying

the inverse matrix by the stiffness matrix.

Physical Analysis

The springs are made of the same elastic solid material, thus making the spring constants the

same. The system of ordinary differential equations satisfied by this system follows from

Newton’s second law of motion is expressed below:


Fig. 2: An explanation of the force diagrams.

We know that at equilibrium, the mass finally reaches its steady state, the equations (1)-(3)

becomes a system of linear algebraic equations of the form:


or, in matrix form:

where, called the stiffness matrix, is:

And:

are the column vectors of the unknown displacements and the known weights, respectively [1]. If

we were to find the inverse of the stiffness matrix, we could multiply it by the stiffness matrix to

get the identity matrix. The inverse means that it can reverse the stiffness matrix and it could be

beneficial to predict the displacements of the same mass-spring system with a different set of

weights. We also found the inverse matrix to be:

0.1 0.1 0.1

0.1 0.15 0.15

0.1 0.15 0.25

Numerical Analysis

The numerical method we used was the LU decomposition with Gauss elimination using dynamic

memory to find the stiffness matrix. To solve a system where Ax=b, the LU decomposition
method involves decomposing A into a product between a lower triangular matrix L and an upper

triangular matrix U. Then, it involves a forward substitution solving Ly=b and a backward

substitution solving Ux=y. We calculated the inverse of the stiffness matrix by changing the b

array values to columns of the identity matric and running the code 3 separate

times so it would print out each column at a time for the inverse matrix.
[1]

Results

We used the LU decomposition code previously mentioned with the values: m1=

10 Kg, m2= 20 Kg, m3= 30 Kg, g= 10 m/s2 and k= 10 Kg/s2.


The matrix entered with these given values was:

30 -20 0

-20 30 -10

0 -10 10

It echoed the two-dimensional array:

The code produced the solution of 60, 85, and 115. After running the code three times with the

changes mentioned previously, it produced the inverse matrix to be:

0.1 0.1 0.1

0.1 0.15 0.15

0.1 0.15 0.25

Conclusion

When encountering vertical spring-mass systems, we understand that we must analyze the forces

applied, combine physics equations, and create a matrix to solve. No matter the amount of

systems inside one larger system, the various components can be solved in this way. By using

C++ coding with LU decomposition, it made it relatively easy to solve for any displacement with

varying weights and a different spring constant. Overall, using these methods allow you to

predict the behavior of mass-spring systems before observing them in reality and could provide

many benefits for engineers by doing so.

References

[1] Dr. Corina S. Drapaca, ESC 261M: Computational Methods for Engineers, Lecture 10 & 11.

Canvas, web. February, 2018.


Appendix

#include <iostream> using

namespace std; typedef double*

IntArrayPtr; void

print(IntArrayPtr *A, int n);

int main() { int n; cout << "Enter the row and column

dimensions or the array:\n"; cin >> n;

IntArrayPtr *m = new IntArrayPtr[n];

int i,

j,k;

for (i = 0; i < n; i++) m[i]

= new double[n];

cout << "Enter " << n << " rows of " << n << " integers each:\n";

for (i = 0; i < n; i++) for (j = 0; j < n; j++) cin >> m[i][j];

cout << "Echoing the two-dimensional array:\n";

for (k=0; k<n-1; k++)

{
for (i=k+1; i<n; i++)

double factor = m[i][k]/m[k][k];

m[i][k]=factor;

for (j=k+1; j<n; j++)

m[i][j]=m[i][j]-factor*m[k][j];

print(m,n);

double sum=0;

double b[3]={100,200,300};

for (i=1; i<n; i++)

{
sum = b[i];

for (j=0; j<=i-1; j++) {

sum = sum - m[i][j] * b[j];

} b[i] = sum; }

double x[3];

x [n-1] = b [n-1] / m[n-1][n-1];

for (i=n-2; i>=0; i--)

sum = 0; for (j=i+1;

j<n; j++) { sum =

sum + m[i][j] *

x[j];

} x[i] = (b[i] - sum) /

m[i][i];

cout << "Solution is: " << endl;


for (i=0; i<n;i++) cout

<< x[i] << endl;

for (i = 0; i < n; i++) delete[] m[i];

delete[] m;

return 0; }

void print(IntArrayPtr *A, int n)

{ for (int i = 0; i < n;

i++) { for (int j = 0; j <

n; j++) cout << A[i][j]

<< " "; cout << endl;

To find inverse:

Run 1 time with b= 100 to get inverse column 1

Run 1 time with b= 010 to get inverse column 2

Run 1 time b= 001 print to get inverse column 3

You might also like