## Problem 2


```python
import numpy as np
import sympy as sp
import scipy as sc
import matplotlib.pyplot as plt
from math import e
%matplotlib inline
```

The given equation is $x(t)=A_1e^{s_1t} + A_2e^{s_2t}$ thus we can find the values of $A_1$ and $A_2$ by <br> substituting $A_2=1-A_1$ and $A_1=\frac{-s_2}{s_1-s_2}$ using the given intital conditions. <br>Then get the values of $s_1$ and $s_2$ from the provided equation for parts A to D using the different values of $a$ and $b$.                    

#### Part A


```python
a=1
b=0.25
s1=-a/2 + np.sqrt((a/2)**2 - b**2)
s2=-a/2 - np.sqrt((a/2)**2 - b**2) 
print("s1=",s1,"s2=",s2)
A1=-s2/(s1-s2)
A2=1-A1
# A1=A2=1
print("A1=",A1,"A2=",A2)
t=np.arange(0,2*np.pi,0.1)
x=A1*(e**(s1*t)) + A2*(e**(s2*t))
# # plt.ylim(-10,10,0.5)
# plt.xlim(-6,6,0.5)
plt.xlabel("Period")
plt.ylabel("x(t)")
plt.plot(t,x)
plt.legend(['for a=1 & b=0.25'])
plt.show()
```

#### Part B


```python
a=-1
b=0.25
s1=-a/2 + np.sqrt((a/2)**2 - b**2)
s2=-a/2 - np.sqrt((a/2)**2 - b**2) 
print("s1=",s1,"s2=",s2)
A1=-s2/(s1-s2)
A2=1-A1
print("A1=",A1,"A2=",A2)
t=np.arange(0,2*np.pi,0.1)
x=A1*(e**(s1*t)) + A2*(e**(s2*t))
plt.xlabel("Period")
plt.ylabel("x(t)")
plt.plot(t,x)
plt.legend(['for a=-1 & b=0.25'])
plt.show()
```

#### Part C


```python
a=1
b=1
s1=complex(-0.5,0.5)
s2=complex(-0.5,-0.5)
print("s1=",s1,"s2=",s2)
A1=-s1/(s1-s2)
A2=1-A1
print("A1=",A1,"A2=",A2)
t=np.arange(0,2*np.pi,0.1)
x=A1.real*(e**(s1.real*t)) + A2.real*(e**(s2.real*t)) #ignoring imaginary parts
plt.xlabel("Period")
plt.ylabel("x(t)")
plt.plot(t,x)
plt.legend(['for a=1 & b=1'])
plt.show()
```

#### Part D


```python
a=-1
b=1
s1=complex(0.5,0.5)
s2=complex(0.5,-0.5)
print("s1=",s1,"s2=",s2)
A1=-s2/(s1-s2)
A2=1-A1
print("A1=",A1,"A2=",A2)
t=np.arange(0,2*np.pi,0.1)
x=A1.real*(e**(s1.real*t)) + A2.real*(e**(s2.real*t)) #ignoring imaginary parts
plt.xlabel("Period")
plt.ylabel("x(t)")
plt.plot(t,x)
plt.legend(['for a=-1 & b=1'])
plt.show()
```

#### Part E


```python
#Undamped oscillation which is pretty much a straight line. 
a=0
b=1
s1=complex(0,1)
s2=complex(0,-1)
print("s1=",s1,"s2=",s2)
A1=-s2/(s1-s2)
A2=1-A1
print("A1=",A1,"A2=",A2)
t=np.arange(0,2*np.pi,0.1)
x=A1.real*(e**(s1.real*t)) + A2.real*(e**(s2.real*t)) #ignoring imaginary parts
plt.xlabel("Period")
plt.ylabel("x(t)")
plt.plot(t,x)
plt.legend(['for a=0 & b=1'])
plt.show()
```

130550299e2eac5d418dcdf5ef605898bc60cf26
ipynb
Jupyter Notebook
1. Single Degree of Freedom Oscillation/1. SDOF Code.ipynb
eyobghiday/mechanical-vibration
fdd5f554464544dcbca8ff96e430f13da4fcceb4
MIT
2022-02-08T18:08:23.000Z
2022-03-13T07:06:01.000Z
1. Single Degree of Freedom Oscillation/1. SDOF Code.ipynb
eyobghiday/mechanical-vibration
fdd5f554464544dcbca8ff96e430f13da4fcceb4
MIT
1. Single Degree of Freedom Oscillation/1. SDOF Code.ipynb
eyobghiday/mechanical-vibration
fdd5f554464544dcbca8ff96e430f13da4fcceb4
MIT
Qwen/Qwen-72B
1. YES
2. YES