自学内容网 自学内容网

Python+Matplotlib-高等数学上-P3-例4


import numpy as np
import matplotlib.pyplot as plt

# Define the functions
def g(x):
    return np.sin(x)

def f(u):
    return np.sqrt(1 - u**2)

def f_composite_g(x):
    return np.abs(np.cos(x))

# Create x values
x = np.linspace(-2*np.pi, 2*np.pi, 1000)

# Create the plot
plt.figure(figsize=(12, 8))

# Plot g(x) = sin(x)
plt.subplot(2, 2, 1)
plt.plot(x, g(x))
plt.title('g(x) = sin(x)')
plt.xlabel('x')
plt.ylabel('g(x)')
plt.grid(True)

# Plot f(u) = sqrt(1 - u^2)
u = np.linspace(-1, 1, 1000)
plt.subplot(2, 2, 2)
plt.plot(u, f(u))
plt.title('f(u) = sqrt(1 - u^2)')
plt.xlabel('u')
plt.ylabel('f(u)')
plt.grid(True)

# Plot (f ∘ g)(x) = |cos(x)|
plt.subplot(2, 2, (3, 4))
plt.plot(x, f_composite_g(x))
plt.title('(f ∘ g)(x) = |cos(x)|')
plt.xlabel('x')
plt.ylabel('(f ∘ g)(x)')
plt.grid(True)

plt.tight_layout()
plt.show()

原文地址:https://blog.csdn.net/naozibuok/article/details/142704191

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!