程序代写代做代考 python Final Exam PHYS248/MATH248¶

Final Exam PHYS248/MATH248¶
Saturday April 14th, 2018, 9am – 12pm (3 hrs)
You are free to use all the course resources, as well as internet sources such as Python documentation web-pages and web search results. You must not have any communications by any means with people, other than the exam invigilators.
If not explicitly stated otherwise, you are free to choose whichever library to use, including your own modules. If you do use your own module, include it in your final exam directory.
Save your final exam (early and often!) in your Bitbucket repository, in mp248/final/final.ipynb.
Please include any other files or modules you will need to make your i-python notebook run in the mp248/final directory.

Problem 1¶

1.1¶
In the Quizzes_Assignments_Exams directory you will find a file sunspots.txt which contains the observed number of sunspots for each month since 1749. Copy that file into the final directory of your repo and commit it along with the other file(s) to your repository. The file contains two columns with the month number and the sunspot number.
Read the data and make a graph as a function of time. The arrays for month and number of sunspots are to be called month and nr_sunsp. Determine how many data point pairs are in the data set and print that number out embedded in a complete and formatted sentence.
Create down sampled data sets month_sparse and nr_sunsp_sparse by retaining only every $15^\mathrm{th}$ data pair. In other words, keep the first data pair, then skip 14, then keep the 15th, and so on.
Plot both the down-sampled data set and the original data set for month 900 to 1700.
In [ ]:

In [ ]:

1.2¶
Plot a histogram of the number of all sunspots with 10 bins. This shows the number times the measured number of sunspots is in each of the 10 sunspot number bins. Extract the data points of the distribution function and overplot with single dots. Make sure that these dots are properly centered for each bin.
In [ ]:

In [ ]:

1.3¶
Fit the sunspot distribution function. Perform a least-square fit of an exponential with three parameters $$ P_\mathrm{spots}(x) = a e^{bx} +c $$ where $x=N_\mathrm{spots}$ is the number of sunspots measured.
Plot the distribution function data and fit together. Round the fit parameters appropriately and write your final fit formula in a Markdown cell.
In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

In [ ]:

Problem 2¶
2.1¶
Write a function that takes as input a positive integer $k$, and uses Sympy to compute the degree $k$ Taylor polynomial for the function $y(x) = sin(x^2)$, centred at $x_0 = 0$, i.e. $T_k(x) = \sum_{i=0}^k\frac{d^i y}{dx^i}(x=0) \frac{x^i}{i!}$. Print the output using a Sympy pprint command, for $k=2,6,10,14,15$.
2.2¶
Write a function that takes as input a positive integer $k$, and uses Sympy to compute the degree $k$ polynomial best fit to $y(x) = sin(x^2)$ on the interval $[0,2\pi]$, using the least-squares technique. As in part 2.1, output your answers for $k=2,6,10,14,15$.
2.3¶
Write a function that takes as input a positive integer $k$. Plot the function $y(x)=sin(x^2)$, together with the corresponding function from 2.1 and 2.2. Include a legend. For your $x$-bounds use the interval $[0, 2\pi]$, for the $y$-bounds use $[-1.2,1.2]$. Label your axis and give your plot an appropriate title (depending on $k$). Include the plot for $k=10$ in your notebook.
In [ ]:

In [ ]:

In [ ]:

Problem 3¶
The Belousov-Zhabotinsky reaction is a chemcial oscillator, a cocktail of chemicals which, when heated, undergoes a series of reactions that cause the chemical concentrations in the mixture to oscillate between two extremes. The following equations describe the evolution of the two concentrations in this chemical system: $$ \frac{dx}{dt} = 1-(b+1)x+ax^2y\\ \frac{dy}{dt} = bx -ax^2y $$ where $x$ and $y$ represent concentrations of two chemicals and $a$ and $b$ are positive constants.
Solve these equations (numerically) for $a=1$, $b=3$ with initial conditions $x=y=0$ and plot the solution.
In [ ]:

In [ ]:

In [ ]:

Problem 4¶
In the data directory there is the text file wdats.txt. Copy this file into your mp248/final directory. Each line of the file has a day of data for Victoria and Saskatoon. The top line of the file explains the content of the remaining lines in the file. In this problem we ask you to make a matplotlib interactive visualization of the data.
Use matplotlib widgets to control your interactive plot. Use a Slider for the user to input the month as a number between 1 (January) and 12 (December). Also have a RadioButton for the user to select between max, min and mean temperatures.
With the application running, when the user selects the month, and clicks on a radio button, the plot should update to show the temperatures for Victoria (horizontal axis) vs Saskatoon (vertical axis) for that month and with the convention chosen on the radio button.
This should be a properly interactive plot, that allows the user to dynamically change the month and radio button, with the plot automatically updating on every change.
If you find using the Slider or RadioButton feature difficult; rather than making an interactive plot, you could opt to make a callable function that takes two arguments: (1) the month as an integer between 1 and 12, and (2) a string ‘Max’, ‘Min’ or ‘Mean’. This function should then make the appropriate non-interactive Matplotlib plot, as described above. Such an answer would receive (at best) a grade of 7/10.
In [ ]:

In [ ]:

In [ ]:

In [ ]: