| | |
| | | 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() |
| | | |