Exponential Functions, Curve Fitting, and Differential Equations

Problem 1. Regression Analysis of a Population Model

We start off Problem 1 by doing the most basic part of any Python programming, which is importing packages and data.  The outside file “expodata” is being brought in from another file in the same directory.  (Note: skiprows is set to 1 so that you don’t have the words in your data set)

Screen Shot 2015-09-28 at 9.10.31 PM

Problem 1 Part 1

 

Next, we had to write a function for the following expression Screen Shot 2015-09-28 at 9.15.41 PM

 

Once again, the first step was to import packages.  The packages that were imported in addition to numpy allow us to see a plot of our data.  I wrote the function itself (called “exponential”) in external file named “expo” (see notes – #Bringing in function from outside file called expo).  We load the data and plot our function to get the following:

Screen Shot 2015-09-28 at 9.46.31 PM

Problem 2 Part 2

 

Part 3 calls for a linear regression.  Once again, we import all necessary packages and our data (expodata).  Then, I linearized the data by using the mathematic function natural log.  We are able to obtain many values from our linear fit, such as the slope, intercept, r value, p value, and standard error.  The data is then converted back to an exponential function which I call “ynew”.  Finally, it is plotted and the data is showed by red circles while the exponential model is a solid black line.

Problem 1 Part 3

Problem 1 Part 3

Next, we used a nonlinear fit to model our data.  Note that we import the optimize module from scipy in order to do this.  The end product of this allowed me to make a prediction for how long it will take the population to reach its doubled size – about 1.04 years.  However, there may be reasons the colony cannot reach this size; for example, a natural disaster or a predator might change their environment and stop them from reproducing as successfully.

Problem 1 Part 4

Problem 1 Part 4

Problem 2. Regression Analysis of Chemical Fate Model

In problem 2, we were asked to repeat a lot of what was done in Problem 1 with different data, called “expodata2” this time.  Again, packages were imported and then the data was brought in.  Instead of bringing in an external file, I defined the function normally.  I used the optimize model again to form a nonlinear curve fit.  Some basic algebra was needed in order to rearrange an equation for half life.  The end product gave a half-life value of 141.4 days (since expodata2 used days instead of years) and the end product is shown below.

Problem 2

Problem 2

Problem 2

Problem 2