This script runs automatically. If loaded to your calculator you not import it to your shell automatically.
Calculates a Leftriemannsum of a set of points. First input your x-values in a list Example: 1,2,3,4 Then input your y-values in a list Example: 1,4,9,16
See sum, and graph.
from math import * from cmath import * from matplotlib.pyplot import * # --- Input Phase --- print("Separated using commas") print("Enter x-values:") x_vals = [float(i) for i in input().split(",")] print("Enter y-values:") y_vals = [float(i) for i in input().split(",")] n = len(x_vals) if len(y_vals) != n: print("Error: x and y must have same length") else: # --- Compute Left Riemann Sum --- total = 0 for i in range(n-1): width = x_vals[i+1] - x_vals[i] total += y_vals[i] * width print("Left Riemann Sum =", total) # --- Wait before plotting --- input("Press Enter to see graph...") # --- Plotting --- x_min = int(min(x_vals)-2) x_max = int(max(x_vals)+2) y_min = int(min(y_vals)-2) y_max = int(max(y_vals)+2) # Plot the (x,y) points axis((x_min,x_max,y_min,y_max)) # Draw left Riemann sum rectangles for i in range(n-1): width = x_vals[i+1]-x_vals[i] bar(x_vals[i]+width/2, y_vals[i], width) text(x_min+0.5,y_max-0.5,"LR="+str(round(total,2))) plot(x_vals, y_vals, color='red',zorder=2) show()