Skip to content

Instantly share code, notes, and snippets.

@khajvahmac
Created February 5, 2017 14:03
Show Gist options
  • Save khajvahmac/12e0e8e0e77285a64d27e8bf09cd1f21 to your computer and use it in GitHub Desktop.
Save khajvahmac/12e0e8e0e77285a64d27e8bf09cd1f21 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
x = np.array([0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.2])
y = np.array([0, 916.6, 1968.8, 2901.2, 3671.4, 4128, 4519.6, 4773.8, 4686.2, 4281.4, 3694])
z = np.polyfit(x, y, 3)
f = np.poly1d(z)
print(f)
#order 6 derivative
z_der = np.array([-5.851*3*10**5, -6.08*2*10**4, 5.418*10**4])
f_der = np.poly1d(z_der)
x_new = np.linspace(x[0], 1, 100)
y_new = f(x_new)
y_der = f_der(x_new)
plt.plot(x, y, 'o', x_new, y_new)
#plt.plot(x_new, y_der)
plt.xlabel("m")
plt.ylabel("N")
plt.suptitle("Force/Deflection(m)")
plt.show()
@khajvahmac
Copy link
Author

khajvahmac commented Feb 5, 2017

Assuming Python 3 is installed, run:
pip install numpy matplotlib to install dependencies.

To run
python spring.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment