hbui
2024-07-21 2f1712ca7e51071caded06570457b722566147b9
num-int/src/numint/main.py
@@ -1,14 +1,32 @@
import matplotlib.pyplot as plt
import sys
from matplotlib import pyplot as plt
from numint.RiemannSum import numint
from numint.input_parser import parse_function, parse_value
def plot_cli(function_expr:str, start:str, end:str, epsilon: str):
    f = parse_function(function_expr)
    (a, b) = (parse_value(start), parse_value(end))
    eps = parse_value(epsilon)
    (x, y, l, r, n) = numint(f, a, b, eps)
    # print(l, r, n)
    plt.step(x, y, label="x^3")
    plt.step(x, y, where="post", label="x^3")
    plt.plot(x, y, color="gray", alpha=0.3)
    plt.show()
    pass
def main():
    def f(x): return x**3
    (a,b) = (1,2)
    (x, y, l, r, n) = numint(f, a, b, 0.5)
    # print(l, r, n)
    plt.step(x, y,               label="x^3")
    plt.step(x, y, where="post", label="x^3")
    plt.plot(x,y, color="gray", alpha=0.3)
    plt.show()
    pass
    function_expr = sys.argv[1]
    start = sys.argv[2]
    end = sys.argv[3]
    eps = sys.argv[4]
    plot_cli(function_expr, start, end, eps)
if __name__ == "__main__":
    main()