# a)
# import libaries
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import quad
# Define the functions f(x) and g(x)
def f(x):
return np.sqrt(x)
def g(x):
return (x - 3) ** 2
# Generate x values between 0 and 5
x_values = np.linspace(0, 5, 400)
# Compute the corresponding y values for both functions
f_values = f(x_values)
g_values = g(x_values)
# Plot the functions
fig, ax = plt.subplots()
plt.figure(figsize=(8, 6))
ax.plot(x_values, f_values, label='f(x) = √x', color='blue')
ax.plot(x_values, g_values, label='g(x) = (x - 3)^2', color='red')
# Labeling the plot
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.legend()
# b)
# The formula for the volume of a solid generated by rotating a region around a vertical line x=0.5 is given by the method of cylindrical shells.
# First we define a function for the shell integrand and then we integrate from 0 to 5.
# This involves integration so we use the scipy library (from scipy.integrate import quad)
# Set boundaries for the integration
a, b = 0, 5
# Define the integrand for cylindrical shells
def integrand_shell(x):
return 2 * np.pi * (x - 0.5) * (f(x) - g(x))
# Perform the integration
volume_shell = quad(integrand_shell, a, b)
print(f"Volume of solid rotating around x = 0.5: {volume_shell[0]}")
# c)
# We need to user the washer method for rotation around a horizontal line 𝑦=5
# First we define a function for the washer integrand and then we integrate from 0 to 5.
# This also involves integration so we use the scipy library (from scipy.integrate import quad)
# Define the integrand for the washer method
def integrand_washer(x):
return np.pi * ((5 - f(x))**2 - (5 - g(x))**2)
# Perform the integration
volume_washer = quad(integrand_washer, a, b)
print(f"Volume of solid rotating around y = 5: {volume_washer[0]}")