Có mã của tôi [tôi nghĩ đó là phương pháp dễ dàng nhất]. Tôi đã làm điều này trong Notebook Jupyter. Mã dễ nhất và chính xác nhất cho phương pháp Simpson là 1/3.
Giải trình
Đối với phương pháp tiêu chuẩn [a = 0, h = 4, b = 12] và f = 100- [x^2]/2
Chúng tôi có: n = 3.0, y0 = 100.0, y1 = 92.0, y2 = 68.0, y3 = 28.0,
Vì vậy, Simpson Method = h/3*[y0+4*y1+2*y2+y3] = 842,7 [điều này không đúng]. Sử dụng quy tắc 1/3 mà chúng tôi có:
h = h/2 = 4/2 = 2 và sau đó:
n = 3.0, y0 = 100.0, y1 = 98.0, y2 = 92.0, y3 = 82.0, y4 = 68.0, y5 = 50.0, y6 = 28.0,
Bây giờ chúng tôi tính toán tích phân cho mỗi bước [n = 3 = 3 bước]:
Tích hợp của bước đầu tiên: h/3*[y0+4*y1+y2] = 389.3333333333333
Tích hợp của bước thứ hai: h/3*[y2+4*y3+y4] = 325.3333333333333
Tích hợp của bước thứ ba: h/3*[y4+4*y5+y6] = 197.3333333333331
Tổng hợp tất cả, và chúng tôi nhận được 912.0 và điều này là đúng
x=0
b=12
h=4
x=float[x]
h=float[h]
b=float[b]
a=float[x]
def fun[x]:
return 100-[x**2]/2
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:] # with every step, we deleting 2 first "y" and we move 2 spaces to the right, i.e. y2+4*y3+y4
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
Lúc đầu, tôi đã thêm mục nhập dữ liệu đơn giản:
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
PHPSimpson 1/3 method is defined using python function definition Evaluate logx dx within limit 4 to 5.2.
First we will divide interval into six equal
parts as number of interval should be even.
x : 4 4.2 4.4 4.6 4.8 5.0 5.2
logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64
Now we can calculate approximate value of integral
using above formula:
= h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 +
1.60 ] +2 *[1.48 + 1.56]]
= 1.84
Hence the approximation of above integral is
1.827 using Simpson's 1/3 rule.
6Enter lower limit of integration: 0
Enter upper limit of integration: 1
Enter number of sub intervals: 6
Integration result by Simpson's 1/3 method is: 0.785398
2 Evaluate logx dx within limit 4 to 5.2.
First we will divide interval into six equal
parts as number of interval should be even.
x : 4 4.2 4.4 4.6 4.8 5.0 5.2
logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64
Now we can calculate approximate value of integral
using above formula:
= h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 +
1.60 ] +2 *[1.48 + 1.56]]
= 1.84
Hence the approximation of above integral is
1.827 using Simpson's 1/3 rule.
87
0.d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
Evaluate logx dx within limit 4 to 5.2.
First we will divide interval into six equal
parts as number of interval should be even.
x : 4 4.2 4.4 4.6 4.8 5.0 5.2
logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64
Now we can calculate approximate value of integral
using above formula:
= h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 +
1.60 ] +2 *[1.48 + 1.56]]
= 1.84
Hence the approximation of above integral is
1.827 using Simpson's 1/3 rule.
96 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
7Evaluate logx dx within limit 4 to 5.2.
First we will divide interval into six equal
parts as number of interval should be even.
x : 4 4.2 4.4 4.6 4.8 5.0 5.2
logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64
Now we can calculate approximate value of integral
using above formula:
= h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 +
1.60 ] +2 *[1.48 + 1.56]]
= 1.84
Hence the approximation of above integral is
1.827 using Simpson's 1/3 rule.
98d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
90
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 1.827847
03Evaluate logx dx within limit 4 to 5.2.
First we will divide interval into six equal
parts as number of interval should be even.
x : 4 4.2 4.4 4.6 4.8 5.0 5.2
logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64
Now we can calculate approximate value of integral
using above formula:
= h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 +
1.60 ] +2 *[1.48 + 1.56]]
= 1.84
Hence the approximation of above integral is
1.827 using Simpson's 1/3 rule.
98
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
06
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.785398
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Bàn luận
Trong phân tích số, quy tắc Simpson 1/3 là một phương pháp xấp xỉ bằng số của các tích phân xác định. Cụ thể, đó là xấp xỉ sau: & nbsp;
the area into n equal segments of width Δx.
Simpson’s rule can be derived by approximating the integrand f [x] [in blue]
by the quadratic interpolant P[x] [in red].
& nbsp; & nbsp;
1.Select a
value for n, which is the number of parts the interval is divided into.
2.Calculate the width, h = [b-a]/n
3.Calculate the values of x0 to xn as x0 = a, x1 = x0 + h, …..xn-1 = xn-2 + h, xn = b.
Consider y = f[x]. Now find the values of y[y0 to yn] for the corresponding x[x0 to xn] values.
4.Substitute all the above found values in the Simpson’s Rule Formula to calculate the integral value.
Approximate value
of the integral can be given by Simpson’s Rule:
Bàn luận
Trong phân tích số, quy tắc Simpson 1/3 là một phương pháp xấp xỉ bằng số của các tích phân xác định. Cụ thể, đó là xấp xỉ sau: & nbsp; In this rule, n must be
EVEN.
Application :
It is used when it is very difficult to solve the given integral mathematically.
This rule gives approximation easily without actually knowing the integration rules.
Example :
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.
C++
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
2& nbsp; & nbsp;
Trong quy tắc 1/3 của Simpson, chúng tôi sử dụng parabolas để xấp xỉ từng phần của đường cong. & nbsp; bởi nội suy bậc hai p [x] [màu đỏ]. & nbsp; & nbsp;
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Để tích hợp bất kỳ hàm f [x] nào trong khoảng [a, b], hãy làm theo các bước được đưa ra dưới đây: 1. Chọn một giá trị cho n, đó là số phần mà khoảng thời gian được chia thành. & Nbsp; 2.Calculation Chiều rộng, h = [b-a] /n 3 Hãy xem xét y = f [x]. Bây giờ tìm các giá trị của y [y0 đến yn] cho các giá trị x [x0 đến xn] tương ứng. được đưa ra bởi quy tắc của Simpson: & nbsp;
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Lưu ý: Trong quy tắc này, n phải chẵn. Ứng dụng: & nbsp; nó được sử dụng khi rất khó để giải quyết tính tích phân đã cho.
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
3 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
4 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
5d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
7d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
9
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
3
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
4Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.7
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.9
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
7d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
9d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853981
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853983
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
3
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
4d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
7d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
9d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853981
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853983
lower_limit
3lower_limit
4
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853987
lower_limit
3upper_limit
0
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
6
lower_limit
3upper_limit
4
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1upper_limit
8
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.0
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.2
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 1.8278474
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
1 lower_limit
2Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
6 lower_limit
1 lower_limit
8
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1f[x]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 sub_interval
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Enter lower limit of integration: 0
Enter upper limit of integration: 1
Enter number of sub intervals: 6
Integration result by Simpson's 1/3 method is: 0.785398
2 sub_interval
4
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 sub_interval
8
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 f[x]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
16
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
05 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
7d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
9d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
26d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
27Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853983
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853987
Các
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
45d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
38 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
40d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
41d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
42Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.2
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
55d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
57lower_limit
3
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.7
lower_limit
3
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.9
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
66d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.2
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
55d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
57Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
66d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81lower_limit
4lower_limit
3lower_limit
1
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
78d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
80lower_limit
3lower_limit
6 lower_limit
1
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
86d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
87 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
88d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
90lower_limit
3lower_limit
6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
92d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
93 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
94Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
04
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
05
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
06d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
92d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
87 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
94
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 sub_interval
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
18
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
01 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
05
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
15
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
16Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
21d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
93d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
26d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
90
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
29d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
37
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
38
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
39
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Python3
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
33
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
34d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
43
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
44
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
45
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
46
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
49
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
45
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
51
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
53
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
55
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
56
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
57
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
58
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
59
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
61
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
63
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
64
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
66
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
63
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
64
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
75
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
76
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
78Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
86Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
80
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
81
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
83
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
84Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
81
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
91
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
66
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
63
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
64
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
75
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
76
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
78Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
80
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
81
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
83
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
84Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
81
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
91
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
93
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
6Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539829
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539811
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71__lower_limit
3
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539817
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
81
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539820
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539822
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
71Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539824
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
87 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539826
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
56Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539829
lower_limit
3
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539817
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
81
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
93
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
83 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539820
lower_limit
3
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539817
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
81
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
87
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
83 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539820
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539848
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
81
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
91
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
93
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
93
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
83 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539857__
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539817
C#
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539864
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54 ________ 193 & nbsp; & nbsp;Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539867
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
29
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539870
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
34
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539873
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539875
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539824
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539877
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
05 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
7d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
9d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
26d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
3 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539879
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853987
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
01 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
02 Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539882
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
05 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
7d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
9Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539896
lower_limit
3
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.7
lower_limit
3
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.9
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.07
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853983
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.78539896
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.07
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853982
Enter lower limit of integration: 0 Enter upper limit of integration: 1 Enter number of sub intervals: 6 Integration result by Simpson's 1/3 method is: 0.7853983
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
37d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
38 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.20
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
45d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
38 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.20
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81upper_limit
0lower_limit
3lower_limit
6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81upper_limit
4Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
upper_limit
8d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
92d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
87 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
94
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 sub_interval
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
01 d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
05
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
15
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
16Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
21d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
93d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
26d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
6d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
90
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
29d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.89
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
38
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
39
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2.
First we will divide interval into six equal
parts as number of interval should be even.
x : 4 4.2 4.4 4.6 4.8 5.0 5.2
logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64
Now we can calculate approximate value of integral
using above formula:
= h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 +
1.60 ] +2 *[1.48 + 1.56]]
= 1.84
Hence the approximation of above integral is
1.827 using Simpson's 1/3 rule.
6Enter lower limit of integration: 0
Enter upper limit of integration: 1
Enter number of sub intervals: 6
Integration result by Simpson's 1/3 method is: 0.785398
2
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
33
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
34d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.95
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
43
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
44
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
45
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
46
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
49
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
45
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
51
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
53
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
54
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
55
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
56
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
57
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
58
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
59
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Các
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
1.82784750
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
401.82784728
1.82784753
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.98
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
401.82784728
1.82784757
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
11.82784761
1.82784762
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.2
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
1.82784728
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
1 Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
1.82784728
lower_limit
3
1.82784761
1.82784787
1.82784750
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
401.82784728
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
42Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
6 lower_limit
1 Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.3
1.82784728
1.82784797
lower_limit
3
1.82784761
lower_limit
001.82784750
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
401.82784728
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
42Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
6lower_limit
3
1.82784761
lower_limit
091.82784750
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
401.82784728
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
42
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
11.82784761
lower_limit
181.82784761
lower_limit
201.82784717
lower_limit
22
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 1.82784761
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
68
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1lower_limit
29 lower_limit
30
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1lower_limit
32 lower_limit
33
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
11.82784713
lower_limit
36
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1lower_limit
38
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
7lower_limit
291.82784710____632
1.82784710
1.82784713
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
06lower_limit
46
JavaScript
lower_limit
47
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.96
lower_limit
50
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 lower_limit
55
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.96
lower_limit
60
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
0Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
64Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
66Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
68Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.2
lower_limit
71lower_limit
3
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.7
lower_limit
3
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.9
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
lower_limit
79Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.2
lower_limit
71lower_limit
3lower_limit
1 lower_limit
2
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81lower_limit
4lower_limit
3lower_limit
6 lower_limit
1 lower_limit
8
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81upper_limit
0lower_limit
3lower_limit
6
d=None
while[True]:
print["Enter your own data or enter the word "test" for ready data.\n"]
x=input ['Enter the beginning of the interval [a]: ']
if x == 'test':
x=0
h=4 #krok [Δx]
b=12 #granica np. 0>12
#w=[20*x]-[x**2] lub [1+x**3]**[1/2]
break
h=input ['Enter the size of the integration step [h]: ']
if h == 'test':
x=0
h=4
b=12
break
b=input ['Enter the end of the range [b]: ']
if b == 'test':
x=0
h=4
b=12
break
d=input ['Give the function pattern: ']
if d == 'test':
x=0
h=4
b=12
break
elif d != -9999.9:
break
x=float[x]
h=float[h]
b=float[b]
a=float[x]
if d == None or d == 'test':
def fun[x]:
return 100-[x**2]/2 #[20*x]-[x**2]
else:
def fun[x]:
w = eval[d]
return w
h=h/2
l=0 #just numeration
print['n=',[b-x]/[h*2]]
n=int[[b-a]/h+1]
y = [] #tablica/lista wszystkich y / list of all "y"
yf = []
for i in range[n]:
f=fun[x]
print['y%s' %[l],'=',f]
y.append[f]
l+=1
x+=h
print[y,'\n']
n1=int[[[b-a]/h]/2]
l=1
for i in range[n1]:
nf=[h/3*[y[+0]+4*y[+1]+y[+2]]]
y=y[2:]
print['Całka dla kroku/Integral for a step',l,'=',nf]
yf.append[nf]
l+=1
print['\nWynik całki/Result of the integral =', sum[yf] ]
81upper_limit
4Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
upper_limit
8Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
2 sub_interval
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
1
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
5Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
upper_limit
08Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
upper_limit
10Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
upper_limit
12Evaluate logx dx within limit 4 to 5.2. First we will divide interval into six equal parts as number of interval should be even. x : 4 4.2 4.4 4.6 4.8 5.0 5.2 logx : 1.38 1.43 1.48 1.52 1.56 1.60 1.64 Now we can calculate approximate value of integral using above formula: = h/3[[ 1.38 + 1.64] + 4 * [1.43 + 1.52 + 1.60 ] +2 *[1.48 + 1.56]] = 1.84 Hence the approximation of above integral is 1.827 using Simpson's 1/3 rule.6
upper_limit
14
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
38
# Simpson's 1/3 Rule
# Define function to integrate
def f[x]:
return 1/[1 + x**2]
# Implementing Simpson's 1/3
def simpson13[x0,xn,n]:
# calculating step size
h = [xn - x0] / n
# Finding sum
integration = f[x0] + f[xn]
for i in range[1,n]:
k = x0 + i*h
if i%2 == 0:
integration = integration + 2 * f[k]
else:
integration = integration + 4 * f[k]
# Finding final integration value
integration = integration * h/3
return integration
# Input section
lower_limit = float[input["Enter lower limit of integration: "]]
upper_limit = float[input["Enter upper limit of integration: "]]
sub_interval = int[input["Enter number of sub intervals: "]]
# Call trapezoidal[] method and get result
result = simpson13[lower_limit, upper_limit, sub_interval]
print["Integration result by Simpson's 1/3 method is: %0.6f" % [result] ]
39upper_limit
17
Output:
1.827847