1. Homepage
  2. Programming
  3. MTHS2008 Advanced Chemical and Environmental Engineering - ASSESSED COURSEWORK 2A - NUMERICAL INTEGRATION

MTHS2008 Advanced Chemical and Environmental Engineering - ASSESSED COURSEWORK 2A - NUMERICAL INTEGRATION

Engage in a Conversation
UKThe University of Nottingham MTHS2008Advanced Chemical and Environmental EngineeringNUMERICAL INTEGRATIONPythonintegral approximationquadrature rulecomposite trapezium rulecomposite Simpson’s rule


ASSESSED COURSEWORK 2A – NUMERICAL INTEGRATION
CourseNana.COM

Rules: CourseNana.COM

Each student is to submit their own coursework.
You are allowed to work together and discuss in small groups (2 to 4 people), but you must write all code by yourself.
CourseNana.COM

You must submit only the .py files requested in this question paper. Details of the required filenames are given within the questions. You are strongly encouraged to use the Spyder IDE (integrated development environment). Hence you should not write IPython Notebooks (.ipynb), and you should not use Jupyter. CourseNana.COM

You may adapt any code that we developed in class (i.e. you do not have to start from scratch). CourseNana.COM

Guidelines for submitting the coursework correctly: CourseNana.COM

For full marks, your functions need to return the correct outputs for the particular input arguments. CourseNana.COM

Please be aware that we will test your functions with an automated marker to check that they work and produce the desired output(s), both with the data given in the question and with different undisclosed data. CourseNana.COM

There is a code testing facility available on Moodle that will help you determine if your modules are producing the correct outputs. We strongly advise you to use this facility prior to submitting your coursework. CourseNana.COM

  • To use this facility, download the test_student_code.py file from Moodle into the same directory as your module files, and then run it through Spyder. An html file should appear in the same directory; you can view this using a web browser.
  • If your code fails to produce valid outputs in the tests of this facility, then it will fail to run through the automarker, and you risk scoring low marks.
  • The code testing facility should show clearly what the particular problem is; but if the warning/error message is not clear, contact the module teacher.
  • The code testing facility does not tell you how many marks you have obtained, it simply shows what outputs your code will produce when passed through the automarker.

If your modules have filenames that differ to what we have explicitly asked for, then your modules will not run through the automarker, and you risk losing marks. CourseNana.COM

• Therefore, please do not add your username or student ID number to your filename. Your functions must have the same inputs and outputs as those specified in the question(s),and in the same order as specified. CourseNana.COM

1. Approximating a single integral:
We have seen that the composite trapezium rule can be written as a weighted sum of function
CourseNana.COM

values at specified points. This representation is given below. CourseNana.COM

? h ?−1?(?)d?2(?(?0)+?(??)+2?(??)), (1) ? ?=1 CourseNana.COM

where h = ? − ? and ?? = ? + h?. ? CourseNana.COM

Your task 1a: CourseNana.COM

Using template_question_1.py (on Moodle) as a template, write a module containing a function single_int_approx(a,b,f,N) to approximate the integral CourseNana.COM

?
?(?)d? (2)
using the composite trapezium rule, as stated in equation (1), for all integer values of ? between 1 and ?, i.e. for 1 to ? strips. CourseNana.COM

These approximations should be saved in an array: the first entry of the array should be the approximation calculated with 1 strip, the second entry should be the approximation calculated with 2 strips, etc, and the final entry should be the approximation calculated with ? strips. CourseNana.COM

The function should take as its inputs ?, ?, ? and ?, where ?, ? and ? correspond to the limits of integration and the integrand from equation (2), and ? is the largest number of strips to be considered. CourseNana.COM

Your module file must be named Q1.py and your function should return one output - the array containing the integral approximations. CourseNana.COM

2. Approximating a double integral: CourseNana.COM

In this question, we introduce a new quadrature rule which, similarly to the composite trapezium rule and composite Simpson’s rule, splits the region of integration into ? strips and can be written as a weighted sum of function values at specified points. This representation is given below. CourseNana.COM

?3
?(?)d?8h(?(?0)+3?(?1)+3?(?2)+2?(?3)+3?(?4)+3?(?5)+2?(?6) CourseNana.COM

+ ⋯+2?(??−3)+3?(??−2)+3?(??−1)+?(??)), CourseNana.COM

3  ?−1 ?/3−1 = 8h?(?0)+?(??)+3?(??)+2 ?(?3?). (3) ?=1 ?=1  ?≠3?   CourseNana.COM

To clarify notation, the first sum of function values ?(??) is for ? values starting from 1 that arenotmultiplesof3(i.e. ?=1,2,4,5,7,8,...)andthesecondsumoffunctionvalues ?(?3?) accounts for the multiples of 3. It is important that when using this quadrature rule, n is a multiple of 3. CourseNana.COM

We have seen that, in 2D, if we wish to integrate ? (?, ?) over a rectangular region ???, ???, then we can use a quadrature rule in each coordinate direction as follows: CourseNana.COM

?
∫ ∫ ?(?,?)d?d?[???(??,?)] d? ? ? ? ?=1 ???? ? ? (? , ? ) = ? ? (? , ? ). ?[? ??]∑∑?? ??  CourseNana.COM

We can apply a numerical quadrature rule in both coordinate directions in this case, but notice that for each quadrature point in the ?-direction, the quadrature points in the ?-direction will change. CourseNana.COM

Your task 2a: CourseNana.COM

Using template_question_2a.py (on Moodle) as a template, write a module containing a function double_int_approx(c,d,x1,x2,f,n) to approximate the double integral CourseNana.COM

? ?2(?) ?(?,?)d?d?, ? ?1(?) CourseNana.COM

using the quadrature rule stated in equation (3) in both coordinate directions. CourseNana.COM

The function should take as its inputs ?, ?, ?1(?), ?2(?), ? and ?, where ?, ?, ?1(?), ?2(?) and ? correspond to the limits of integration and the integrand from equation (4), and ? is the number of strips to be used in the approximation (you may assume that the same number of strips is to be used in each coordinate direction, but remember that ? must be a multiple of 3). CourseNana.COM

Test: CourseNana.COM

To test that your code is working as expected, compute an approximation for CourseNana.COM

2?∫ ∫ ?2?d?d? 1 −?
for ? = 12. For the weights in the ?-direction, you should obtain the array given below CourseNana.COM

[0.03125, 0.09375, 0.09375, 0.0625 , 0.09375, 0.09375, 0.0625 [0.09375, 0.09375, 0.0625 , 0.09375, 0.09375, 0.03125] CourseNana.COM

and for the approximation of the double integral, you should obtain a value of CourseNana.COM

4.13334297839506. CourseNana.COM

Your task 2b: CourseNana.COM

Using template_question_2b.py (on Moodle) as a template, write a module containing a function plot_region(c,d,x1,x2,n) to create a figure containing the plot of the region of integration for the double integral CourseNana.COM

? ?2(?) ?(?,?)d?d?. ? ?1(?) CourseNana.COM

In order for the automarker to generate figures using your code, you need to return the figure as an output. To do so, give the figure a ‘handle’ when you create it, i.e. assign it to a variable. For example CourseNana.COM

fig = plt.figure()
You can then return the figure to the user using the command return fig. CourseNana.COM

Your module file must be named Q2b.py and your function should return one output - the figure containing the plot of the region of integration. CourseNana.COM

Test: CourseNana.COM

To test that your code is working as expected, plot the region of integration for the double integral CourseNana.COM

2?∫ ∫ ?2?d?d? 1 −?
with ? = 12. You should be able to verify the accuracy of your plot by sketching the region of integration by hand. CourseNana.COM

You can check that your code works for this example by running the test_student_code.py provided on Moodle. Please note that your code will be run for several examples when it is being marked, not just the stated test example, so you are encouraged to test your code using your own examples also. CourseNana.COM

[7 marks] CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
UK代写,The University of Nottingham 代写,MTHS2008代写,Advanced Chemical and Environmental Engineering代写,NUMERICAL INTEGRATION代写,Python代写,integral approximation代写,quadrature rule代写,composite trapezium rule代写,composite Simpson’s rule代写,UK代编,The University of Nottingham 代编,MTHS2008代编,Advanced Chemical and Environmental Engineering代编,NUMERICAL INTEGRATION代编,Python代编,integral approximation代编,quadrature rule代编,composite trapezium rule代编,composite Simpson’s rule代编,UK代考,The University of Nottingham 代考,MTHS2008代考,Advanced Chemical and Environmental Engineering代考,NUMERICAL INTEGRATION代考,Python代考,integral approximation代考,quadrature rule代考,composite trapezium rule代考,composite Simpson’s rule代考,UKhelp,The University of Nottingham help,MTHS2008help,Advanced Chemical and Environmental Engineeringhelp,NUMERICAL INTEGRATIONhelp,Pythonhelp,integral approximationhelp,quadrature rulehelp,composite trapezium rulehelp,composite Simpson’s rulehelp,UK作业代写,The University of Nottingham 作业代写,MTHS2008作业代写,Advanced Chemical and Environmental Engineering作业代写,NUMERICAL INTEGRATION作业代写,Python作业代写,integral approximation作业代写,quadrature rule作业代写,composite trapezium rule作业代写,composite Simpson’s rule作业代写,UK编程代写,The University of Nottingham 编程代写,MTHS2008编程代写,Advanced Chemical and Environmental Engineering编程代写,NUMERICAL INTEGRATION编程代写,Python编程代写,integral approximation编程代写,quadrature rule编程代写,composite trapezium rule编程代写,composite Simpson’s rule编程代写,UKprogramming help,The University of Nottingham programming help,MTHS2008programming help,Advanced Chemical and Environmental Engineeringprogramming help,NUMERICAL INTEGRATIONprogramming help,Pythonprogramming help,integral approximationprogramming help,quadrature ruleprogramming help,composite trapezium ruleprogramming help,composite Simpson’s ruleprogramming help,UKassignment help,The University of Nottingham assignment help,MTHS2008assignment help,Advanced Chemical and Environmental Engineeringassignment help,NUMERICAL INTEGRATIONassignment help,Pythonassignment help,integral approximationassignment help,quadrature ruleassignment help,composite trapezium ruleassignment help,composite Simpson’s ruleassignment help,UKsolution,The University of Nottingham solution,MTHS2008solution,Advanced Chemical and Environmental Engineeringsolution,NUMERICAL INTEGRATIONsolution,Pythonsolution,integral approximationsolution,quadrature rulesolution,composite trapezium rulesolution,composite Simpson’s rulesolution,