#Program to evaluate integration using Trapezoidal rule
from math import*
def f(x):
y=exp(-x*x)
return y
a=input("Enter the lower limit:")
b=input("Enter the upper limit:")
n=input("Enter the no. of divisions:")
a=float(a)
b=float(b)
n=int(n)
h=(b-a)/(n*1.)
s=0
for i in range(1,n):
s=s+f(a+i*h)
y=(h/2)*(f(a)+f(b)+2*s)
print("The value of the integration is:",y)
from math import*
def f(x):
y=exp(-x*x)
return y
a=input("Enter the lower limit:")
b=input("Enter the upper limit:")
n=input("Enter the no. of divisions:")
a=float(a)
b=float(b)
n=int(n)
h=(b-a)/(n*1.)
s=0
for i in range(1,n):
s=s+f(a+i*h)
y=(h/2)*(f(a)+f(b)+2*s)
print("The value of the integration is:",y)
Comments
Post a Comment