Mar-27-2019, 01:43 PM
Thanks,
I am also trying to graph the error vs h with a loglog function, but I have two separate issues.
loglog is not recognized and when I omit it, the graph I obtain is empty.
I am also trying to graph the error vs h with a loglog function, but I have two separate issues.
loglog is not recognized and when I omit it, the graph I obtain is empty.
from scipy import * import numpy as np from numpy import array from scipy import integrate import matplotlib.pyplot as plt a=0 b=1 n=500 h=(b-a)/(n) def f(x): return x**2 def trapezoidal(f,a,b,n): return (h/2)*(f(a)+f(b))+h*( sum(f(a+h*i) for i in range(1, (n-1)))) print(trapezoidal(f,a,b,n)) # Why this? lambda x: f(x) c= integrate.quad(f,0,1) print(c) error=(abs(trapezoidal(f,a,b,n)-c[0]) for n in range (300,900)) print(list(error)) plt.plot((list(error),list(h)) for n in range (300,900))