fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. def quadratic_function(a, b, c, x_range=(-10, 10), num_points=100):
  5. x = np.linspace(x_range[0], x_range[1], num_points)
  6. y = a * x**2 + b * x + c
  7.  
  8. plt.figure(figsize=(8, 6))
  9. plt.plot(x, y, label=f'y = {a}x² + {b}x + {c}', color='b')
  10. plt.axhline(0, color='black', linewidth=0.5)
  11. plt.axvline(0, color='black', linewidth=0.5)
  12. plt.grid(True, linestyle='--', alpha=0.6)
  13. plt.legend()
  14. plt.xlabel('x')
  15. plt.ylabel('y')
  16. plt.title('Quadratic Function')
  17. plt.show()
  18.  
  19. # 例: y = x^2 - 3x + 2 を描画
  20. quadratic_function(1, -3, 2)
Success #stdin #stdout #stderr 3.41s 68364KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Fontconfig error: No writable cache directories