fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. def gnu_plot(a, b, x_min, x_max):
  5. """
  6. Plots the function ax^2 + bx using Matplotlib.
  7.  
  8. Args:
  9. a: Coefficient of the x^2 term.
  10. b: Coefficient of the x term.
  11. x_min: Minimum value of x for the plot.
  12. x_max: Maximum value of x for the plot.
  13. """
  14.  
  15. x = np.linspace(x_min, x_max, 100) # Generate 100 points between x_min and x_max
  16. y = a * x**2 + b * x
  17.  
  18. plt.plot(x, y)
  19. plt.xlabel('x')
  20. plt.ylabel('y')
  21. plt.title('GNU Plot of ax^2 + bx')
  22. plt.grid(True)
  23. plt.show()
  24.  
  25. # Example usage:
  26. a = 2
  27. b = -5
  28. x_min = -3
  29. x_max = 3
  30.  
  31. gnu_plot(a, b, x_min, x_max)
  32.  
Success #stdin #stdout 0.72s 55348KB
stdin
import numpy as np
import matplotlib.pyplot as plt

def gnu_plot(a, b, x_min, x_max):
    """
    Plots the function ax^2 + bx using Matplotlib.

    Args:
        a: Coefficient of the x^2 term.
        b: Coefficient of the x term.
        x_min: Minimum value of x for the plot.
        x_max: Maximum value of x for the plot.
    """

    x = np.linspace(x_min, x_max, 100)  # Generate 100 points between x_min and x_max
    y = a * x**2 + b * x

    plt.plot(x, y)
    plt.xlabel('x')
    plt.ylabel('y')
    plt.title('GNU Plot of ax^2 + bx')
    plt.grid(True)
    plt.show()

# Example usage:
a = 2
b = -5
x_min = -3
x_max = 3

gnu_plot(a, b, x_min, x_max)
, 
stdout
Standard output is empty