GEOL 5470

Homework/Labwork                                                                                                  Humphrey                                                            Integration

Our previous program took the derivative of a curve.  The curve could have been derived from math (we did the math route), or more realistically some real data that you needed to find the gradient (slope) or the derivative curve.  Here we investigate integration, again we use math to get some data to integrate, but again we could use actual data.

1.       Cut and paste from your sine plotting program to make a new program that plots the sine curve and then plots its integral.  There are, of course, a dozen numpy methods that will integrate for you, (actually the best are in the more inclusive SciPy.integrate module, such as the ‘quad()’ method)  but again we are going to do it the hard way.  Integrating is taking the area under the curve.  There are many fancy ways of doing this, but the easiest is to consider the area under each step of the curve to be a trapezoid and just add all the areas.  You should be able to write a ‘for’ loop to integrate any curve.  As a hint, the area of a vertical slice of a plotted curve is ½ the sum of the two vertical heights times the width of the slice.  We will talk about higher order techniques for both integrating and differentiating, but this introduces the topic.  When you are done, you can plot the resulting integral curve of the sine, along with the analytic solution.  If you need ideas, you can look at the ‘Week 1 Homework’ example code on our web pages.

2.    (Optional) If you want to push ahead a little,  ‘from scipy.integrate import quad’, and then use quad() to integrate the sine curve.  To pass the sine function to the quad function you just write it as the first argument: quad(np.sin,…..).