From 2f1712ca7e51071caded06570457b722566147b9 Mon Sep 17 00:00:00 2001 From: hbui <hong-phuc.bui@htwsaar.de> Date: Sun, 21 Jul 2024 09:51:57 +0200 Subject: [PATCH] plot cli OK --- num-int/src/numint/main.py | 38 ++++++++++++++++++++++++++++---------- 1 files changed, 28 insertions(+), 10 deletions(-) diff --git a/num-int/src/numint/main.py b/num-int/src/numint/main.py index e61dd6c..0353729 100644 --- a/num-int/src/numint/main.py +++ b/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 \ No newline at end of file + 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() + -- Gitblit v1.10.0-SNAPSHOT