Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial upload of work from monday. #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions students/one-pavelG/data/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
3 -4.621424
3.25 -5.804482
3.5 -6.70809
3.75 -7.398549
4 -7.922563
4.25 -8.316091
4.5 -8.606262
4.75 -8.813852
5 -8.954821
5.25 -9.042461
5.5 -9.08705
5.75 -9.0977
6 -9.07705
6.25 -9.03505
6.5 -8.9743
6.75 -8.8984
7 -8.8103
7.25 -8.7122
7.5 -8.60665
7.75 -8.4949
8 -8.3785
8.25 -8.2585
8.5 -8.1362
8.75 -8.0118
9 -7.88685
9.25 -7.7615
9.5 -7.63665
9.75 -7.51265
10 -7.3898

4 changes: 4 additions & 0 deletions students/one-pavelG/data/data_p.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

v= [3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25, 5.5, 5.75, 6, 6.25, 6.5, 6.75, 7, 7.25, 7.5, 7.75, 8, 8.25, 8.5, 8.75, 9, 9.25, 9.5, 9.75, 10]

e= [-4.621424, -5.804482, -6.70809, -7.398549, -7.922563, -8.316091, -8.606262, -8.813852, -8.954821, -9.042461, -9.08705, -9.0977, -9.07705, -9.03505, -8.9743, -8.8984, -8.8103, -8.7122, -8.60665, -8.4949, -8.3785, -8.2585, -8.1362, -8.0118, -7.88685, -7.7615, -7.63665, -7.51265, -7.3898]
37 changes: 37 additions & 0 deletions students/one-pavelG/instructions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Project One: a simple data analyiss program and using git.

The goal of the first project is to write a complete program to read in x-y data from a file and calculate least squares regression to this data. We will first do a linear regression using a parabolic model. Later we will add a nonlinear regression using a solid state equation of state called the Murnaghan equation.

While developing your program you are tracking your development using git.
Commit your project apporixmately after you have achieved the following milestones.

Before you start do these 2 steps.
1- Initialize your name and email for git (see cheat sheet):

git config --global user.name "[name]"
git config --global user.email "[email address]"

2- Copy the project directory projects/one into the student subdirectory with your initial added like

cp -r projects/one students/one-gs

Work and make changes in this directory only.

1 - Read the data from file and create x and y data.
2 - Add a plot of your data.
3 - Perform a linear regression to a parabolic function using for example
(numpy/polyfit)
Update your graph.
Extract the minimum and the curvature from your linear regression.

4 - Observe the performance of your regression and think about the validity of a quadratic approximation. Improve your linear regression by restricting your data to a few points (how many is reasonable?) around the minimum.

Optional:

5 - Perform a nonlinear regression to the Murnaghan equation of state
(wikipedia: https://en.wikipedia.org/wiki/Murnaghan_equation_of_state)
using for example (numpy/curvefit) Update your graph.



45 changes: 45 additions & 0 deletions students/one-pavelG/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np
import matplotlib.pyplot as plt

data = np.loadtxt('data/data.txt')

X = data[:,0]
Y = data[:, 1]

coef = np.polyfit(X, Y, 2)
fit = np.poly1d(coef)
fitted_data = fit(X)


f, ax = plt.subplots()
ax.scatter(X, Y, label = 'Real Data')
ax.plot(X, fitted_data, label = 'Quadratic Fit')
ax.set_title('Quadratic Fit Plot')
ax.legend()
plt.show()


crit = fit.deriv().r

print('If we complete the square on the equation we get the following formula:')
print('0.226729 * (x − 6.74078)^2 − 9.14145')
print('Which means the minimum point of the fitted parabola is at X =', crit)
print('and the curvature is 0.226729')

X_alt = X[5:16]
Y_alt = Y[5:16]

coef_alt = np.polyfit(X_alt, Y_alt, 2)
fit_alt = np.poly1d(coef_alt)
fitted_data_alt = fit_alt(X_alt)


f, ax = plt.subplots()
ax.scatter(X_alt, Y_alt, label = 'Real Data')
ax.plot(X_alt, fitted_data_alt, label = 'Quadratic Fit')
ax.set_title('Modified Quadratic Fit Plot')
ax.legend()
plt.show()

print('Using a subsection of the data allows for a closer fit as')
print('the data is much more quadratic on the left side of the mininum')