0
0
SciPydata~10 mins

Romberg integration in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Romberg integration function from scipy.

SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Aromberg
Btrapz
Cquad
Dsimps
Attempts:
3 left
💡 Hint
Common Mistakes
Importing quad instead of romberg.
Using integration functions unrelated to Romberg.
2fill in blank
medium

Complete the code to define the function f(x) = x^2 for integration.

SciPy
def f(x):
    return x[1]2
Drag options to blanks, or click blank then click option'
A+
B**
C*
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of ** for power.
Using + or // which are incorrect here.
3fill in blank
hard

Fix the error in calling romberg to integrate f from 0 to 1.

SciPy
result = romberg(f, [1], 1)
Drag options to blanks, or click blank then click option'
A1
Bf
C0
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the limits or passing the function instead of a limit.
Using 1 as the first limit which is the upper limit.
4fill in blank
hard

Fill both blanks to compute Romberg integration of sin(x) from 0 to pi.

SciPy
import numpy as np
result = romberg(np.[1], 0, [2])
Drag options to blanks, or click blank then click option'
Asin
Bcos
Cnp.pi
De
Attempts:
3 left
💡 Hint
Common Mistakes
Using cosine instead of sine.
Using e instead of pi as upper limit.
5fill in blank
hard

Fill all three blanks to create a dictionary of Romberg results for functions over [0, 1].

SciPy
functions = {'square': lambda x: x[1]2, 'cube': lambda x: x[2]3}
results = {name: romberg(func, 0, 1) for name, func in functions.items() if func(0) == [3]
Drag options to blanks, or click blank then click option'
A**
B*
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication * instead of exponentiation **.
Checking if function(0) equals 1 instead of 0.