jet_ski.py

Created by nick-koberstein

Created on September 22, 2021

629 Bytes


from math import *
import matplotlib.pyplot as plt

def f(x):
  return 100*x+10
a = 0; b = 0.5; N = 5
n = 10 # Use n*N+1 points to plot the function smoothly
step = (b-a)/N
s = (b-a)/(n*N)


x = [0]*(N+1)
x[0]=a
for i in range(1,N+1):
  x[i]=x[i-1]+step
  
y = [0]*(N+1)
for i in range(N+1):
  y[i] = f(x[i])

X = [0]*(n*N)
X[0]=a
for i in range(1,n*N):
  X[i]=X[i-1]+s

Y = [0]*(n*N)
for i in range(n*N):
  Y[i] = f(X[i])

plt.plot(X,Y,'r')
x_left = x[:-1] # Left endpoints
y_left = y[:-1]
x_plot = [0]*(N)
for i in range (N):
  x_plot[i] = x[i]+.05

plt.bar(x_plot,y_left, 0.1,color="red")
plt.grid()

plt.show()