Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python coding question Numerical integration Be sure to watch the Numerical integration video before starting this section Many functions in engineering and presies cannot be

Python coding question
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Numerical integration Be sure to watch the Numerical integration video before starting this section Many functions in engineering and presies cannot be integrated analytical to you can't wite down the result of the integration using dementary functions. However, any function can be integrated to some specified Decision using a computer. This is the topic that we shall now explore The algorithm One of the most baske integration algorithmes e Traperiun Rule (also known as the Traperoldat Rull, where the interfirbo is approximated by evaluating fat a sequence of uniformly spaced in the the range connecting the points by straightines, and summing the weas of the trapeziums so formed For example, p.) ==-Kiu' + ir + the value of Shots can be calculated by summing the areas of the ten orange trapezums shown in the following tgure, where the spacing between sampes, Ar. 1808 The area of a traperiun with widm A, and edige heights of her and is given by Thus in general the numeric approximation to an integru Cum where a = to and bass gwen by Since al but the most and rightmost values of your appear twice in this summation, more efficient representations are possible, but the above will suffice for our purposes Note: If you're unter with the summation rotation used in the above equation you can think of it os rendez NOTIC) Ar+M+S) Aru)1(es) Ar+E + Wine a function trapezion_Letegratoram, bet started run train that uses the Trapezium Rule to evaluate the integral where start, and and are defined in the formule above, and e_trans is the number of traumthat the integration intervishould be divided into Notes: . You may astune sort and 1 We are expecting you to compute the width of each traperiun and then use for loop to solve the problem. Iterating over the traperuma to sum their sten. A more efficient proach, using pumpy and avoiding any explicit oops is the topic of one of the challenge wuestions If you have traperlom, the width of each traperium will be law, it may help to sketch out a simple example on paper to get you started For example: Result + A simple case with only trapets 9.5000 You may want to drw what you are computing on per a trapezion_Integratori, 2., 6., 2., 3) printareat.61) Another single case with a straight line 3.000000 area traperiun integratori0.5, 1.0, 2.0, 4.0.2 Brimareal.)") strerin integrator. 2.0.0.0, 1.0.0) 0.13333 printf(ant.61") Answer: tensity regie 0.10,20... Numerical Integration Be sure to watch the Numerical Integration video before starting this section! Many functions in engineering and physics cannot be integrated analytically, i.e., you can't write down the result of the integration using elementary functions. However, any function can be integrated, to some specified precision, using a computer. This is the topic that we shall now explore. The algorithm One of the most basic integration algorithms is the Trapezium Rule (also known as the Trapezoidal Rule), where the integral de (r)dr is approximated by evaluating f(r) at a sequence of uniformly spaced points in the the range [a,b], connecting the points by straight lines, and summing the areas of the trapeziums so formed. For example, if f(x) = - 8.5r + 18.5x + 4 the value of Si(r)dr can be calculated by summing the areas of the ten orange trapeziums shown in the following figure, where the spacing between samples, Ar, is 0.5. 30 25 20 f(x) 15 10 5 2 The area of a trapezium with width Ar and edge heights of hrafe and hright is given by Atrapezium= Ar Thus in general the numerical approximation to an integral Lif(r)dr where a = 10 and b = y, is given by (*)drl=;)+{n+) Ar HA Since all but the leftmost and rightmost values of f(x) appear twice in this summation, more efficient representations are possible, but the above will suffice for our purposes. Note: If you're unfamiliar with the summation notation used in the above equation, you can think of it as (rcayde 316dS24 MG)Elled as the f(02 ()dx=()F() x; f(+() Ax+ + Write a function trapezium_integrator(alpha, beta, start, end, num_traps) that uses the Trapezium Rule to evaluate the integral ar dr Jxtul where alpha, beta, start, and end are defined in the formula above, and num_traps is the number of trapeziums that the integration interval should be divided into. Notes: . You may assume 0) = 1. We are expecting you to compute the width of each trapezium and then use a for loop to solve this problem, iterating over the trapeziums to sum their areas. A more efficient approach, using numpy and avoiding any explicit loops, is the topic of one of the challenge questions. If you have 11 trapeziums, the width of each trapezium will be (end - start). It may help to sketch out a simple example on paper to get you started. For example: Test Result 9.500000 # A simple case with only 3 trapeziums. # You may want to draw what you are computing on paper. area = trapezium_integrator (1.0, 2.0, 0.0, 3.0, 3) print(f"{area:.6f}") # Another simple case with a straight line. area = trapezium_integrator(0.5, 1.0, 2.0, 4.0, 2) print("{area:.6f}") ans = trapezium_integrator(1.0, 2.0, 0.0, 1.0, 9999) print (f"{ans:.6f}") 3.000000 0.333333

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

c. Will leaders rotate periodically?

Answered: 1 week ago

Question

b. Will there be one assigned leader?

Answered: 1 week ago