Simpson Method

Simpson's 2 rule: It is referred to as Simpson's 3/8 rule.

In this segment, we will explore both Simpson's rules and demonstrate the sample code for each of them.

Simpson's 1/3 Rule

It is alternatively referred to as Simpson's Rule, which defines the following principle:

where f(x) represents the function to be integrated, a denotes the starting point, and b signifies the endpoint for the integration process.

Quadratic Interpolation

Replace the function f(x) with a quadratic polynomial P(x), which represents a parabolic curve and matches the values of f(x) at the limits a and b. Additionally, ensure that P(x) evaluates m = (a + b)/2 just like f(x). Consequently, by employing Lagrange Polynomial Interpolation and integration through substitution, we arrive at:

Then utilize a step size of h=(b-a)/2, which can be expressed as:

As it represents a 1/3 factor, this method is commonly referred to as Simpson's rule or Simpson's 1/3 rule.

The Simpson's rule is formulated based on the diagram below, where the integral of f(x) is estimated using P(x), a quadratic interpolant.

Numerical Example

For resolving a mathematical problem, we must employ the Simpson's rule, which is ```

include<stdio.h>

include<conio.h>

include<math.h>

define f(x) 1/(1+x*x)

int main

{

float lower, upper, intgrl=0.0, stepSize, k;

int i, subInterval;

clrscr;

printf("Enter lower integration limit: ");

scanf("%f", &lower);

printf("Enter upper integration limit: ");

scanf("%f", &upper);

printf("Enter sub intervals: ");

scanf("%d", &subInterval);

stepSize = (upper - lower)/subInterval;

intgrl = f(lower) + f(upper);

for(i=1; i<= subInterval-1; i++)

{

k = lower + i*stepSize;

if(i%2==0)

{

intgrl = intgrl + 2 * f(k);

}

else

{

intgrl= intgrl + 4 * f(k);

}

}

intgrl = intgrl * stepSize/3;

printf("The integration is: %.3f", intgrl);

getch;

return 0;

}

Example


Numerical: Calculate the definite integral of log(x) dx over the interval from 4 to 5.2.

Solution:

Step 1: Select a specific value to determine the division of intervals, denoted as n. Therefore, in this particular scenario, the initial action involves segmenting the interval into six identical sections, as it is necessary for the intervals to be an even number.

Step 2: Calculate the value of h = (b - a)/2

Evaluate and compute the values of x 0 to x n based on the function y = f(x). Next, determine the corresponding values of y 0 to y n within the range of x 0 to x n. The data obtained is as follows:

Step 3: Insert the provided values into the function, and subsequently, we will be able to compute an estimated value of the integral by applying the formula mentioned earlier:

= h/3[( 1.38 + 1.64) + 4 * (1.43 + 1.52 +

1.60 ) +2 *(1.48 + 1.56)]

= 1.84

Therefore, the estimation of the aforementioned integral is 1.827 when applying Simpson's 1/3 rule.

### Program Implementation for Simpson's 1/3 Rule

Below is the code implementation in C for Simpson's one-third rule:

include<stdio.h>

include<conio.h>

include<math.h>

define f(x) 1/(1+x*x)

int main

{

float lower, upper, intgrl=0.0, stepSize, k;

int i, subInterval;

clrscr;

printf("Enter lower integration limit: ");

scanf("%f", &lower);

printf("Enter upper integration limit: ");

scanf("%f", &upper);

printf("Enter sub intervals: ");

scanf("%d", &subInterval);

stepSize = (upper - lower)/subInterval;

intgrl = f(lower) + f(upper);

for(i=1; i<= subInterval-1; i++)

{

k = lower + i*stepSize;

if(i%2==0)

{

intgrl = intgrl + 2 * f(k);

}

else

{

intgrl= intgrl + 4 * f(k);

}

}

intgrl = intgrl * stepSize/3;

printf("The integration is: %.3f", intgrl);

getch;

return 0;

}

Example


The output of the above code is shown below:

Enter lower integration limit: Enter upper integration limit: Enter sub intervals: The integration is: %.3f

Example


## Simpson 3/8 Rule

It represents the second principle in Simpson's rule and bears resemblance to the Simpson 1/3 rule, albeit with a notable contrast. Unlike the 1/3 rule, the 3/8 rule in Simpson's method involves using a cubic polynomial as the interpolant. Described as the Simpson 3/8 rule, it can be articulated as follows:

where f(x) represents the function being integrated, and h denotes the width of the interval, determined by the formula h = (b - a)/n, where n signifies the number of intervals.

Now, let's explore the program execution to grasp the rationale behind the Simpson 3/8 rule.

### Program to implement Simpson 3/8 rule

Below is the program code implementation in C++:

include<stdio.h>

include<conio.h>

include<math.h>

define f(x) 1/(1+x*x)

int main

{

float lower, upper, intgrl=0.0, stepSize, k;

int i, subInterval;

clrscr;

printf("Enter lower limit integration limit: ");

scanf("%f", &lower);

printf("Enter upper integration limit: ");

scanf("%f", &upper);

printf("Enter sub intervals: ");

scanf("%d", &subInterval);

stepSize = (upper - lower)/subInterval;

intgrl = f(lower) + f(upper);

for(i=1; i<= subInterval-1; i++)

{

k = lower + i*stepSize;

if(i%3 == 0)

{

intgrl = intgrl + 2 * f(k);

}

else

{

intgrl= intgrl + 3 * f(k);

}

}

intgrl = intgrl stepSize3/8;

printf("The integration is: %.3f", intgrl);

getch;

return 0;

}

Example


The output of the above code is shown below:

Enter lower integration limit: Enter upper integration limit: Enter sub intervals: The integration is: %.3f

Example


In addition to the previously mentioned two principles of Simpson, there is a third rule applicable in the field of naval architecture and the assessment of ship stability. Nonetheless, this rule holds little significance in more general contexts.

Input Required

This code uses input(). Please provide values below: