<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Homework 2
Taylor Patti
2/15/2015
Excercises Completed
Exercise 5.18 (fit_pendulum_data.py)
Exercise 5.22 (midpoint_vec.py)
Exercise 5.23 (Lagrange_poly1.py)
Exercise 5.24 (Lagrange_poly2.py)
Exercise 5.25 (Lagrange_poly2b.py)
fit_pendulum_data
Provides various functions which facilitate the harvesting of data from a separate file, the plotting of this data,
and the creation of composite plots consisting of this data and polynomial fits thereof of various orders. Ultimately,
the third order polynomial had the best fit, although only marginally so over the 2nd order. This seems pretty common though;
that a higher order polynomial usually beats out its competitors, especially over small data sets, even if they are more physically relevant.
Step1:  midpoint_vec
This module called for the design of a midpoint integration function in three separate implementations, one list iterative, one semi-vectorized, and one fully vectorized. The supreme accuracy of this algorithm is illustrated in the sine integration below. The purpose of devising 3 different implementations was to be able to compare their relative efficiency. As denoted below, the list iterative midpointint function faired the fastest, most likely due to the relatively small number of iterations required. Moreover, the fully vectorized midpointvec was faster than the semi-vectorized midpointvecdefault, most likely due to the superior efficiency of the numpy sum function. Had the number of elements in these iterations been greater, the fully vectorized version would have faired better than both of its counterpart functions.
Step2:  Lagrange_poly1
In this module, the Lagrange Interpolation Formula was used to construct an interpolating function; a function who takes in n data points and devises an nth order polynomial which it then implements to extrapolate the value of all points within the boundaries of the data set, whether included or not. This first excercise shows how accurate this process is, with the interpolating function returning a nearly perfect value for the sine function when the input is given at the midpoint between two of the data points provided.
Step3:  Lagrange_poly2
A graphing function was constructed that permitted the simultaneous plotting of the actual function and the interpolating function, both with indicated interval perpherations.
Step4:  Lagrange_poly3
The oscillatory shortcomings of high peripheration interpolating functions is demonstrated by the creation of two plots. The first shows how the general fit quality increases with greater peripheration frequency while this quantity is reasonably small. The later indicates that too many terms can result in wild oscillations at the end points of the function indicated.
<ASSISTANT_TASK:>
Python Code:
p1.pendulum_plotter()
p1.poly_plotter()
Explanation: Homework 2
Taylor Patti
2/15/2015
Excercises Completed
Exercise 5.18 (fit_pendulum_data.py)
Exercise 5.22 (midpoint_vec.py)
Exercise 5.23 (Lagrange_poly1.py)
Exercise 5.24 (Lagrange_poly2.py)
Exercise 5.25 (Lagrange_poly2b.py)
fit_pendulum_data
Provides various functions which facilitate the harvesting of data from a separate file, the plotting of this data,
and the creation of composite plots consisting of this data and polynomial fits thereof of various orders. Ultimately,
the third order polynomial had the best fit, although only marginally so over the 2nd order. This seems pretty common though;
that a higher order polynomial usually beats out its competitors, especially over small data sets, even if they are more physically relevant.
End of explanation
p2.midpointvec(np.sin, 0, np.pi/2, 1000)
%timeit p2.midpointint(p2.x_func, 1, 3, 1000)
%timeit p2.midpointvecdefault(p2.x_func, 1, 3, 1000)
%timeit p2.midpointvec(p2.x_func, 1, 3, 1000)
Explanation: midpoint_vec
This module called for the design of a midpoint integration function in three separate implementations, one list iterative, one semi-vectorized, and one fully vectorized. The supreme accuracy of this algorithm is illustrated in the sine integration below. The purpose of devising 3 different implementations was to be able to compare their relative efficiency. As denoted below, the list iterative midpointint function faired the fastest, most likely due to the relatively small number of iterations required. Moreover, the fully vectorized midpointvec was faster than the semi-vectorized midpointvecdefault, most likely due to the superior efficiency of the numpy sum function. Had the number of elements in these iterations been greater, the fully vectorized version would have faired better than both of its counterpart functions.
End of explanation
xp = np.linspace(0, math.pi, 5)
yp = np.sin(xp)
middle = xp[2] - xp[1] / 2
print 'Function interpolates: ',
print p3.p_L(middle, xp, yp)
print 'Actual sine result is: ',
print math.sin(middle)
Explanation: Lagrange_poly1
In this module, the Lagrange Interpolation Formula was used to construct an interpolating function; a function who takes in n data points and devises an nth order polynomial which it then implements to extrapolate the value of all points within the boundaries of the data set, whether included or not. This first excercise shows how accurate this process is, with the interpolating function returning a nearly perfect value for the sine function when the input is given at the midpoint between two of the data points provided.
End of explanation
p4.graph(np.sin, 5, 0, math.pi)
Explanation: Lagrange_poly2
A graphing function was constructed that permitted the simultaneous plotting of the actual function and the interpolating function, both with indicated interval perpherations.
End of explanation
p5.multigrapher()
Explanation: Lagrange_poly3
The oscillatory shortcomings of high peripheration interpolating functions is demonstrated by the creation of two plots. The first shows how the general fit quality increases with greater peripheration frequency while this quantity is reasonably small. The later indicates that too many terms can result in wild oscillations at the end points of the function indicated.
End of explanation
<END_TASK>