Im trying to format the output for this calculation but it keeps giving my an error for the line where Im formatting i saying i is undefined, Im guessing its something to do with i being used in the definition but Im not entirely sure and also not sure how to get it to recognize it.
There could be a problem with my n, Im trying to get it to double each time in the range to 512 so not sure if thats the problem but Im also working on trying to figure that out and not sure if thats affecting i
What I have tried:
Theres some more code before this just getting input and defining more definitions but I dont think its relevant to the problem.
def my_trap(a,b,n):
sum= 0
h= (b-a)/n
for i in range(1,n+1):
x=a+i*h
sum=sum+2*f(x)
return (h/2)*(sum+f(a)+f(b))
print('\nThis programme estimates the integral of the function sin(x) in the \
integral [a,b] using the trapezoidal method.')
a=getinput('a')
b=getinput('b')
n=512/2
n=n*2
error= analytical(a,b)-my_trap(a,b,n)
print('{0:<20}'.format(i),'|'\
'{0:<20.5f}'.format(my_trap(a,b,n)), '|', \
'{0:<20.5f}'.format(error))