Math 9 Spring 2023 Final Project Description
Approximation of Pi
This final project serves as the open-note programming final exam of this course, counting 10 points in total grades, and with a possibility of 1.5 bonus credit at maximum (described below). The “stepsize” in grading is 0.5, meaning that whenever one requirement below is not satisfied, at least 0.5 points will be subtracted. It also means your answer should be perfect in order to receive the possible bonus credits.
Submission: upload the report in the format of Matlab livescript file to Canvas. The submission should be a well-organized report (with well-structured sections, clear figures and necessary descriptions as text in the livescript file, with all code blocks already executed). Submitting merely the codes and/or incomplete results will severely impact your grades. Please include everything in one single mlx file, and any other formats (.pdf, .doc ...or even .m script /Jupyter notebook) or redundant files are not valid and won’t be graded. Please define all the functions in the livescript.
Your report should address all the tasks as follows (not necessarily follow the order, but all the required parts should be included in the report).
Task 1 (1pt)
Give your report an appropriate title reflecting its scientific contents (don’t simply name it as Math9 Final Project).
Write your student id and name under title.
Acknowledging the final project policy by reading and copying the following paragraph (displayed in Italic font) at the beginning of your report and keeping the requirements in your mind.
I hereby confirm that the present report is my own work and that I am not allowed to seek help from anyone else in this project. If any texts or codes from books, papers, the Web or any other sources have been copied or in any other way used, all references have been acknowledged and cited. I am aware that the instructor has the authority to report and investigate any potential academic misconduct in this course, and such misconduct could lead to failing this course. If I have employed any AI models (including but not limited to ChatGPT), I have appropriately and explicitly acknowledged their use in the report whenever the results were generated with the aid of AI.
Task 2 (6pt)
In this final project, the major aim is to approximate the digits of pi with different numerical methods. Throughout the quarter, we have learned many different ways: 1) through numerical integral (left-end/right-end/midpoint/trapezoidal), for example ∫$ √1 − 𝑥! = ", 2) infinite series %# as appeared in Homework 3, 3) Monte-Carlo methods in lecture 7. In the final report, it’s required to implement at least six methods (Different numerical integral formulas can be counted as different methods. Different infinite series can also be counted as different methods). You may find useful resources here
https://en.wikipedia.org/wiki/Approximations_of_%CF%80
Below are the specific requirements:
Define the in-script function calculate_pi(method, n) which outputs the scalar that approximates pi. The input method could either be a character/string or a number, representing the different methods you’re using (at least six options should be provided), and the input n might have different meanings for each method. For example, n denotes number of integrals in the integration method, the total terms in the infinite series method, and the number of random simulations/steps/points in Monte-Carlo method.
(1pt) Write the function with correct input and output form as the in-script function. Under the function name, add function description as comments below the function definition line (followed with %). In the description, especially elaborate on the input of “method”, to at least include 1) what are the possible choices 2) how to call the function to use each method 3) what does input n exactly mean in each method.
(3pt) Write the correct codes for each method to approximate the pi (hint: you may need to use if or switch to let user specify different methods).
(2pt) In the live script, for each of the method your function supported, 1) introduce the formula/method used with text and equations, 2) use some code lines as the example to show how to use your calculate_pi function to realize the method, and obtain a reasonable estimation of pi (to display digits better, please use format long). If the method is not introduced in this course, please include the sources. Reminder : 1) Don’t use any method that does not involve iterations or repetitions (i.e. the input n in your defined function must be meaningful in each method) in calculating pi (for example, it’s NOT good to use some direct formula such as 22/7 and other formulas appeared in “Miscellaneous approximations” or “Machin-like formula” section of https://en.wikipedia.org/wiki/Approximations_of_%CF%80)
2) It’s okay to define as many as function upon your convenience. However, the calculate_pi function itself should support at least six choices of methods, instead of defining six separate functions. 3) Make sure that the function outputs the approximated pi instead of other values (e.g. pi/4). Matlab variable pi is not allowed to appear in the function.
Task 3 (2pt+0.5 bonus credit)
Now start with a separate section in the livescript. For each method, use the defined function to explore the relationship between n and absolute error to approximate pi (use matlab variable pi as the ground truth – although it’s not perfect) similar to what you did in Homework 4. Plot such relation for different methods in one figure with correct axis labels (hint: you might need logarithm scale to better illustrate the results. Consult and modify the provided code in Homework 4 to generate plot). Describe your observation with texts in live script. For some Monte-Carlo methods, the result could be “noisy”, and that is totally acceptable as long as you faithfully describe what you observe and the code is correct.
(Optional 0.5pt bonus) Fitting the quantitative relation between n and absolute error for each method, and you might earn 0.5 bonus points if this can be satisfactorily and appropriately implemented. Note that for some methods, the relationship might no longer be linear, therefore the input to polyfit should be adjusted accordingly. You may also use other functions in matlab to fit the trend. To get the bonus point, please describe in detail with texts about how you fit the quantitative relation, and what is the conclusion. Merely calling the function without detailed explanation is not sufficient to get bonus points.
Hint: some methods (e.g. infinite series) are highly efficient to calculate the digits. Therefore, you might include some very small n in the calculation to observe the trend.
Task 4 (1pt): organizing and formatting your report well in live script.
1) Organize your report in sections/subsections with section titles in the format of different heading levels. The section titles should NOT be like “Task 1”, “Task 2” ... but instead reflecting the scientific contents in each section. If you have addressed this appropriately, the table of contents can be automatically inserted at the beginning of the report to reflect its structure. Generate such a table of contents after the acknowledgement part. 2) Do not submit with a live script with merely codes. Imagine you’re writing a report/manual for users/even a thesis. Add text whenever it is necessary. The texts should at least cover 1) Motivation and background (brief introduction to the history of pi approximation, what’s your goal in this report) 2) the formula you used – you must type them in the livescript, 3) Explanation about how to use the function you defined to calculate pi, 4) and all other texts required in Task 2-3. 3) Figures generated in this report should have clear and correct axis labels.
4) It’s OK to use online materials (including codes), but make sure you fully understand them and cite them. Task 5 (Bonus 1pt): Use Python to address all the tasks above within a Jupyter notebook file. The grading policy for this bonus point is at the discretion of instructor and a near-perfect report (including text, figure, and codes) is expected in order to get the bonus point (submit through a separate assignment) More References: History of Pi: https://en.wikipedia.org/wiki/Pi#cite_note-137