We have learned the mid-point and trapezoidal rule for numercial intergration in the tutorials. Now you are asked to implement the Simpson rule, where we approximate the integration of a non-linear curve using piecewise quadratic functions. Assume f(x) is continuous over [a, b]. Let [a, b] be divided into N subintervals, each of length A.x, with endpoints at P = x0, x1,x2,..., X, XN. Each interval is Ax = (b-a)/N. The equation for the Simpson numerical integration rule is derived as: f f(x)dx [f(x) + 4 (Emln odd f(x)) + 2 (E-2n even f(x)) + f(x)]. Now complete the Python function InterageSimpson (N, a, b) below to implement this Simpson rule using the above equation. The function to be intergrate is f(x) = 2x³ (Already defined in the function, no need to change).

Elements Of Electromagnetics
7th Edition
ISBN:9780190698614
Author:Sadiku, Matthew N. O.
Publisher:Sadiku, Matthew N. O.
ChapterMA: Math Assessment
Section: Chapter Questions
Problem 1.1MA
icon
Related questions
Question
Markdown
Validate
Complete the function given the variables N, a,b and return the value as "Totalarea".
"Don't change the predefined content' only fill your code in the region 'YOUR CODE'"
from math import *
def InterageSimpson (N, a, b): # n is the total intervals, a and b is the lower and upper bound respectively
"""Hint: Use loop to add all the values in the above equation and
use the if statement to determine whether the value is odd or even"""
$
ܠ
def f(x):
## The function f(x)=2*x**3 is defined as below, DON'T CHANGE IT:
f=2*x**3
return f
return TotalArea
####Check your code by using print command below###
| Idle Mem: 262.63/12288.00 MB
N=100
a=1
b=3
value=0 # Initial value
TotalArea=0 # TotalArea as the final integral value, the area underneath the curve.
dx=(b-a)/N # delta x, the interval length
# Complete the function by filling your codes below:
# YOUR CODE HERE
print (InterageSimpson (N, a, b))
[ ]: ## Don't write any code in this box
[ ]: ## Don't write any code in this box
[ ]: ## Don't write any code in this box
[ ]: ## Don't write any code in this box
Q
R
F4
FL
%
5
g
F5
T
G
^
6
# Make sure in your solution, you use the same name "TotalArea" for the output
F6
Y
H
&
7
F7
U
* 0
8
Mode: Command
DII
F8
(
9
K
X
DD
F9
Ln 1, Col 1 English (United States) Python_coursework.ipynb
)
0
J
A
F10
0 P
I
4
5
F11
0 Python 3 (pyk
{
[
11
4)
F12
}
]
E
Transcribed Image Text:Markdown Validate Complete the function given the variables N, a,b and return the value as "Totalarea". "Don't change the predefined content' only fill your code in the region 'YOUR CODE'" from math import * def InterageSimpson (N, a, b): # n is the total intervals, a and b is the lower and upper bound respectively """Hint: Use loop to add all the values in the above equation and use the if statement to determine whether the value is odd or even""" $ ܠ def f(x): ## The function f(x)=2*x**3 is defined as below, DON'T CHANGE IT: f=2*x**3 return f return TotalArea ####Check your code by using print command below### | Idle Mem: 262.63/12288.00 MB N=100 a=1 b=3 value=0 # Initial value TotalArea=0 # TotalArea as the final integral value, the area underneath the curve. dx=(b-a)/N # delta x, the interval length # Complete the function by filling your codes below: # YOUR CODE HERE print (InterageSimpson (N, a, b)) [ ]: ## Don't write any code in this box [ ]: ## Don't write any code in this box [ ]: ## Don't write any code in this box [ ]: ## Don't write any code in this box Q R F4 FL % 5 g F5 T G ^ 6 # Make sure in your solution, you use the same name "TotalArea" for the output F6 Y H & 7 F7 U * 0 8 Mode: Command DII F8 ( 9 K X DD F9 Ln 1, Col 1 English (United States) Python_coursework.ipynb ) 0 J A F10 0 P I 4 5 F11 0 Python 3 (pyk { [ 11 4) F12 } ] E
-
Python 3 (pyke
We have learned the mid-point and trapezoidal rule for numercial intergration in the tutorials. Now you are asked to implement the
Simpson rule, where we approximate the integration of a non-linear curve using piecewise quadratic functions.
Assume f(x) is continuous over [a, b]. Let [a, b] be divided into N subintervals, each of length Ax, with endpoints at
P= x0, x1,x2,..., Xn,...,xN. Each interval is Ax = (b-a)/N.
$
The equation for the Simpson numerical integration rule is derived as:
df(xn)) + 2 (Σ=2n even
Now complete the Python function InterageSimpson (N, a, b) below to implement this Simpson rule using the above equation.
The function to be intergrate is f(x) = 2x³ (Already defined in the function, no need to change).
Sof(x)dx≈ [f(x) + 4 (N=
[]: 'Complete the function given the variables N, a,b and return the value as "TotalArea". "
"Don't change the predefined content only fill your code in the region 'YOUR CODE"
a
Idle Mem: 262.63/12288.00 MB
F4
R
from math import *
def InterageSimpson (N, a, b): # n is the total intervals, a and b is the lower and upper bound respectively
"""Hint: Use loop to add all the values in the above equation and
use the if statement to determine whether the value is odd or even"""
LL
def f(x):
## The function f(x)=2*x**3 is defined as below, DON'T CHANGE IT:
f=2*x**3
return f
value=0 # Initial value
TotalArea=0 # TotalArea as the final integral value, the area underneath the curve.
dx=(b-a)/N # delta x, the interval length.
# Complete the function by filling your codes below:
# YOUR CODE HERE
return TotalArea # Make sure in your solution, you use the same name "TotalArea" for the output
####Check your code by using print command below###
%
5
9
F5
n=1,n odd -
T
G
6
C
F6
Y
H
&
F7
f(x₂)) + f(xN)].
U
*
8
Mode: Command Ⓡ
DII
F8
K
(
9
F9
0
Ln 1, Col 1 English (United States) Python_coursework.ipynb
)
O
♫
F10
P
:
4
F11
{
+ 11
11
F12
}
1
E
Transcribed Image Text:- Python 3 (pyke We have learned the mid-point and trapezoidal rule for numercial intergration in the tutorials. Now you are asked to implement the Simpson rule, where we approximate the integration of a non-linear curve using piecewise quadratic functions. Assume f(x) is continuous over [a, b]. Let [a, b] be divided into N subintervals, each of length Ax, with endpoints at P= x0, x1,x2,..., Xn,...,xN. Each interval is Ax = (b-a)/N. $ The equation for the Simpson numerical integration rule is derived as: df(xn)) + 2 (Σ=2n even Now complete the Python function InterageSimpson (N, a, b) below to implement this Simpson rule using the above equation. The function to be intergrate is f(x) = 2x³ (Already defined in the function, no need to change). Sof(x)dx≈ [f(x) + 4 (N= []: 'Complete the function given the variables N, a,b and return the value as "TotalArea". " "Don't change the predefined content only fill your code in the region 'YOUR CODE" a Idle Mem: 262.63/12288.00 MB F4 R from math import * def InterageSimpson (N, a, b): # n is the total intervals, a and b is the lower and upper bound respectively """Hint: Use loop to add all the values in the above equation and use the if statement to determine whether the value is odd or even""" LL def f(x): ## The function f(x)=2*x**3 is defined as below, DON'T CHANGE IT: f=2*x**3 return f value=0 # Initial value TotalArea=0 # TotalArea as the final integral value, the area underneath the curve. dx=(b-a)/N # delta x, the interval length. # Complete the function by filling your codes below: # YOUR CODE HERE return TotalArea # Make sure in your solution, you use the same name "TotalArea" for the output ####Check your code by using print command below### % 5 9 F5 n=1,n odd - T G 6 C F6 Y H & F7 f(x₂)) + f(xN)]. U * 8 Mode: Command Ⓡ DII F8 K ( 9 F9 0 Ln 1, Col 1 English (United States) Python_coursework.ipynb ) O ♫ F10 P : 4 F11 { + 11 11 F12 } 1 E
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Elements Of Electromagnetics
Elements Of Electromagnetics
Mechanical Engineering
ISBN:
9780190698614
Author:
Sadiku, Matthew N. O.
Publisher:
Oxford University Press
Mechanics of Materials (10th Edition)
Mechanics of Materials (10th Edition)
Mechanical Engineering
ISBN:
9780134319650
Author:
Russell C. Hibbeler
Publisher:
PEARSON
Thermodynamics: An Engineering Approach
Thermodynamics: An Engineering Approach
Mechanical Engineering
ISBN:
9781259822674
Author:
Yunus A. Cengel Dr., Michael A. Boles
Publisher:
McGraw-Hill Education
Control Systems Engineering
Control Systems Engineering
Mechanical Engineering
ISBN:
9781118170519
Author:
Norman S. Nise
Publisher:
WILEY
Mechanics of Materials (MindTap Course List)
Mechanics of Materials (MindTap Course List)
Mechanical Engineering
ISBN:
9781337093347
Author:
Barry J. Goodno, James M. Gere
Publisher:
Cengage Learning
Engineering Mechanics: Statics
Engineering Mechanics: Statics
Mechanical Engineering
ISBN:
9781118807330
Author:
James L. Meriam, L. G. Kraige, J. N. Bolton
Publisher:
WILEY