Which of the following methods is used for finding roots of an equation by approximating them iteratively?
Which numerical method is used to estimate the definite integral of a function?
Which numerical method involves dividing the interval into smaller subintervals and approximating the integral using quadratic polynomials?
Which numerical method is based on the idea of linear interpolation?
Which of the following numerical methods can be used to find the maximum or minimum value of a function within a given interval?
What will be the output of the following code snippet?
import math
def newton_method(f, df, x0, tol):
x = x0
while abs(f(x)) > tol:
x = x - f(x) / df(x)
return x
f = lambda x: x**3 - x - 1
df = lambda x: 3 * x**2 - 1
root = newton_method(f, df, 1, 1e-6)
print(root)
What will be the output of the following code snippet?
import math
def simpsons_rule(f, a, b, n):
h = (b - a) / n
sum1 = f(a) + f(b)
sum2 = 0
sum3 = 0
for i in range(1, n):
x = a + i * h
if i % 2 == 0:
sum2 += f(x)
else:
sum3 += f(x)
return (h / 3) * (sum1 + 2 * sum2 + 4 * sum3)
f = lambda x: math.sin(x)
a = 0
b = math.pi / 2
n = 10
result = simpsons_rule(f, a, b, n)
print(result)
Consider the following equation: f(x) = x^2 - 4x + 3. Using Newton's method, what is the value of x0 that will converge to one of the roots of the equation if started from x0 = 2? (Note: df denotes the derivative of f)
Consider the following equation: f(x) = x^3 - 2x^2 - 11x + 12. Using the bisection method, how many iterations are required to approximate the root within an error tolerance of 0.001 if the initial interval is [2, 4]?
Consider the function f(x) = x^2 - 4x + 4. Which numerical method can be used to find the minimum value of f(x) in the interval [0, 5]?
What will be the output of the following code snippet?
import math
def newton_method(f, df, x0, tol):
x = x0
while abs(f(x)) > tol:
x = x - f(x) / df(x)
return x
f = lambda x: x**3 - 2 * x - 2
df = lambda x: 3 * x**2 - 2
root = newton_method(f, df, 2, 1e-5)
print(root)
What will be the output of the following code snippet?
import math
def simpsons_rule(f, a, b, n):
h = (b - a) / n
sum1 = f(a) + f(b)
sum2 = 0
sum3 = 0
for i in range(1, n):
x = a + i * h
if i % 2 == 0:
sum2 += f(x)
else:
sum3 += f(x)
return (h / 3) * (sum1 + 2 * sum2 + 4 * sum3)
f = lambda x: math.sin(x)
a = 0
b = math.pi / 2
n = 4
result = simpsons_rule(f, a, b, n)
print(result)
Consider the following equation: f(x) = x^3 + x^2 - 5x - 3. Using the bisection method, how many iterations are required to approximate the root within an error tolerance of 0.001 if the initial interval is [-2, 0]?
Consider the following equation: f(x) = x^2 - 2. Using Newton's method, what is the value of x0 that will converge to one of the roots of the equation if started from x0 = 2? (Note: df denotes the derivative of f)
Consider the function f(x) = x^3 - x^2 - 2x + 1. Which numerical method can be used to find the maximum value of f(x) in the interval [0, 2]?