From f3ff117fbe9f70a2a5d9b6dcd2f1d7cbd52311b8 Mon Sep 17 00:00:00 2001 From: grechasneak Date: Mon, 1 Oct 2018 14:26:15 -0700 Subject: [PATCH 1/4] made my folder --- students/one-pavelG/data/data.txt | 30 ++++++++++++++++++++++ students/one-pavelG/data/data_p.txt | 4 +++ students/one-pavelG/instructions.txt | 37 ++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 students/one-pavelG/data/data.txt create mode 100644 students/one-pavelG/data/data_p.txt create mode 100644 students/one-pavelG/instructions.txt diff --git a/students/one-pavelG/data/data.txt b/students/one-pavelG/data/data.txt new file mode 100644 index 0000000..3d43213 --- /dev/null +++ b/students/one-pavelG/data/data.txt @@ -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 + diff --git a/students/one-pavelG/data/data_p.txt b/students/one-pavelG/data/data_p.txt new file mode 100644 index 0000000..96b0368 --- /dev/null +++ b/students/one-pavelG/data/data_p.txt @@ -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] diff --git a/students/one-pavelG/instructions.txt b/students/one-pavelG/instructions.txt new file mode 100644 index 0000000..35cf566 --- /dev/null +++ b/students/one-pavelG/instructions.txt @@ -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. + + + From e72d59e0197ce06de0936763d21739ef65c13dd2 Mon Sep 17 00:00:00 2001 From: grechasneak Date: Mon, 1 Oct 2018 14:53:32 -0700 Subject: [PATCH 2/4] wrote my code --- students/one-pavelG/script.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 students/one-pavelG/script.py diff --git a/students/one-pavelG/script.py b/students/one-pavelG/script.py new file mode 100644 index 0000000..1b230b4 --- /dev/null +++ b/students/one-pavelG/script.py @@ -0,0 +1,22 @@ +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('Example Plot') +ax.legend() +plt.show() + +#print('Mininum point on linear regression is:', min(fitted_data)) From 959089fd15dafbe95f6d61e29cba09a656c15ef7 Mon Sep 17 00:00:00 2001 From: grechasneak Date: Mon, 1 Oct 2018 15:10:38 -0700 Subject: [PATCH 3/4] added curvature code --- students/one-pavelG/script.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/students/one-pavelG/script.py b/students/one-pavelG/script.py index 1b230b4..7ceccbb 100644 --- a/students/one-pavelG/script.py +++ b/students/one-pavelG/script.py @@ -19,4 +19,12 @@ ax.legend() plt.show() -#print('Mininum point on linear regression is:', min(fitted_data)) + +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') From b7ecb67ade4c017086a231fb99612aedc211c235 Mon Sep 17 00:00:00 2001 From: grechasneak Date: Mon, 1 Oct 2018 15:16:43 -0700 Subject: [PATCH 4/4] Added part 4 --- students/one-pavelG/script.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/students/one-pavelG/script.py b/students/one-pavelG/script.py index 7ceccbb..508897f 100644 --- a/students/one-pavelG/script.py +++ b/students/one-pavelG/script.py @@ -7,7 +7,6 @@ Y = data[:, 1] coef = np.polyfit(X, Y, 2) - fit = np.poly1d(coef) fitted_data = fit(X) @@ -15,16 +14,32 @@ f, ax = plt.subplots() ax.scatter(X, Y, label = 'Real Data') ax.plot(X, fitted_data, label = 'Quadratic Fit') -ax.set_title('Example Plot') +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')