Integration
Integration
03/23/2023
PREPARED BY: ER. KOBID KARKEE
Lab 9:
Numerical Integration Using
Trapezoidal, Simpson’s 1/3,
Simpson’s 3/8
Trapezoidal Method 2
Algorithm
03/23/2023
PREPARED BY: ER. KOBID KARKEE
1. Start
2. Declare the necessary variables and define the function
f(x).
3. Input the lower limit and upper limit as a and b
respectively.
4. Input the number of strips as n.
5. Compute the value of strip width as h = (b-a)/n.
6. Set sum = f(a) + f(b)
Trapezoidal Method 3
7. Begin for i=1 to n-1
03/23/2023
PREPARED BY: ER. KOBID KARKEE
sum = sum + 2*f(a + i*h)
End for i
8. sum = sum*h/2
9. Display sum as the integral value.
10. Stop
Pseudo Code 4
03/23/2023
PREPARED BY: ER. KOBID KARKEE
Input lower limit a, upper limit b, number of strips n
Define function f(x)
Calculate h = (b-a)/n
sum = f(a) + f(b)
Do for i = 1 : n-1
sum = sum + 2* f(a + i * h)
End for i
sum= (h/2)*sum
Print sum
Simpson’s 1/3 Method
5
Algorithm
03/23/2023
PREPARED BY: ER. KOBID KARKEE
1. Start
2. Declare the necessary variables and define the function f(x).
3. Input the lower limit and upper limit as a and b respectively.
4. Input the number of strips as n (where n is even).
5. Compute the value of strip width as h = (b-a)/n.
6. sum = f(a) + f(b)
Simpson’s 1/3 Method
6
7. for i=1 to n-1
03/23/2023
PREPARED BY: ER. KOBID KARKEE
if (i%2==0)
sum = sum + 2*f(a+i*h)
else
sum = sum + 4*f(a+i*h)
end i
8. sum= (h/3)*sum
9. Display sum as the integration value.
10. Stop
Pseudo Code
Input lower limit a, upper limit b, number of strips n 7
Define function f(x)
03/23/2023
PREPARED BY: ER. KOBID KARKEE
Calculate h = (b-a)/n
sum = f (a) + f (b)
For i = 1 : n-1
if(i%2==0)
sum = sum + 2*f( a + i * h)
else
sum = sum + 4*f( a + i * h)
end if
End for i
sum = (h/3)*sum
Print sum
Simpson’s 3/8 Rule 8
Algorithm
03/23/2023
PREPARED BY: ER. KOBID KARKEE
1. Start
2. Declare the necessary variables and define the function f(x).
3. Input the lower limit and upper limit as a and b respectively.
4. Input the number of strips as n where n is a multiple of 3.
5. Compute the value of strip width as h = (b-a)/n.
6. sum = f(a) + f(b)
Simpson’s 3/8 Rule 9
03/23/2023
PREPARED BY: ER. KOBID KARKEE
if (i%3==0)
sum = sum + 2*f(a + i*h)
else
sum = sum + 3*f(a + i*h)
end i
8. sum = (3*h/8)*sum
9. Display sum as the integral value.
10. Stop
Pseudo Code 10
Input lower limit a, upper limit b, number of strips n
Define function f(x)
03/23/2023
PREPARED BY: ER. KOBID KARKEE
Calculate h = (b-a)/n
sum = f (a) + f (b)
For i = 1 : n-1
if(i%3==0)
sum = sum + 2*f( a + i * h)
else
sum = sum + 3*f( a + i * h)
End if
End for i
sum = (3*h/8)*sum
Print sum