0
0
SciPydata~10 mins

Single integral (quad) 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 function for numerical integration.

SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Aquad
Bintegrate
Csolve
Ddiff
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'integrate' which is the module, not the function.
Using 'solve' which is unrelated to integration.
Using 'diff' which is for differentiation.
2fill in blank
medium

Complete the code to define the function to integrate: f(x) = x^2.

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 '^' which is bitwise XOR, not power.
Using '*' which is multiplication, not power.
3fill in blank
hard

Fix the error in the integration call to integrate f from 0 to 1.

SciPy
result, error = quad([1], 0, 1)
Drag options to blanks, or click blank then click option'
Af()
Bf(x=0)
Cf(x)
Df
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function with parentheses inside quad.
Passing a function call instead of the function object.
4fill in blank
hard

Fill both blanks to print the integral result and the estimated error.

SciPy
print('Integral:', [1])
print('Error estimate:', [2])
Drag options to blanks, or click blank then click option'
Aresult
Berror
Cresult[0]
Derror[1]
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to index result or error as if they were lists.
Using wrong variable names.
5fill in blank
hard

Fill all three blanks to compute and print the integral of sin(x) from 0 to pi.

SciPy
import numpy as np
from scipy.integrate import [1]

result, error = [2](np.[3], 0, np.pi)
print(result)
Drag options to blanks, or click blank then click option'
Aquad
Csin
Dcos
Attempts:
3 left
💡 Hint
Common Mistakes
Using cosine instead of sine.
Using different names for import and call.