Weddle’s Rule C Program

By | October 31, 2017

Let us learn how to implement Weddle’s rule algorithm in C programming with its explanation, output and much more.

What is Weddle’s Algorithm Rule?

The Weddle’s algorithm was designed by Thomas Weddle. This algorithm is a simple method of integration.

The number of sub intervals required in the Weddle’s rule is 6. As compared to other numerical integration algorithms, the Weddle’s algorithm offers a very good efficiency.

Weddle’s Rule Formula

C Program For Weddle's Rule Formula

Weddle’s Rule Algorithm

Step 1: Input Lower limit, Upper limit and Number of Intervals
Step 2: Calculate Interval Gap (Interval Gap = (Upper limit - Lower limit) / Interval)
Step 3: If(Interval % 6==0)
              sum = sum + ((3 * interval_gap / 10) * (y(Lower limit) + y(Lower limit + 2 * interval_gap) + 5 * y(Lower limit + interval_gap) 
              + 6 * y(Lower limit + 3 * interval_gap) + y(Lower limit + 4 * interval_gap) + 5 * y(Lower limit + 5 * interval_gap) + y(Lower limit + 6 * interval_gap)));
              Lower limit = Lower limit + 6 * interval_gap;
        Go To Step 5.
        Else
              Weddle’s rule is not applicable
Step 5: Evaluated Result

Note: This C program for Weddle’s rule in numerical integration is compiled with GNU GCC compiler using CodeLite IDE on Microsoft Windows 10 operating system.

C Program For Weddle’s Rule Algorithm

#include<stdio.h>

float calc(float temp)
{
      float value;
      value = 1 / (1 + temp * temp);
      return (value);
}   
                       
int main()
{
      int interval, limit, count = 0;
      float upper_limit, lower_limit, interval_gap, sum = 0;
      printf("\nLower Limit:\t");
      scanf("%f", &lower_limit);
      printf("\nUpper Limit:\t");
      scanf("%f", &upper_limit);
      printf("\nTotal Intervals:\t");
      scanf("%d", &interval);
      interval_gap = (upper_limit - lower_limit) / interval;
      printf("\nInterval Gap:\t%f\n", interval_gap);
      limit = interval / 6;
      if(interval % 6 == 0)
      {
            while(count < limit)
            {
                  sum = sum + ((3 * interval_gap / 10) * (calc(lower_limit) + calc(lower_limit + 2 * interval_gap) + 5 * calc(lower_limit + interval_gap) + 
                        6 * calc(lower_limit + 3 * interval_gap) + calc(lower_limit + 4 * interval_gap) + 5 * calc(lower_limit + 5 * interval_gap) + 
                        calc(lower_limit + 6 * interval_gap)));  
                        lower_limit = lower_limit + 6 * interval_gap;  
                  count = count + 1;
            }
            printf("\nWeddle's Rule is satisfied.\n\nEvaluated Result:\t%f\n", sum);
      }
      else
      {
            printf("\nThe Weddle's Rule is not satisfied\n");
      }      
      return 0;   
}

Output

Weddle's Rule Algorithm in C Programming

If you have any doubts about the implementation of Weddle’s rule formula in C programming, let us know about it in the comment section. Find more about it on Wolfram.

NUMERICAL METHODS C PROGRAMS
Newton-Raphson Method C Program
Euler’s Method C Program
Secant Method C Program
Bisection Method C Program
Gauss Seidel Method C Program
Simpson’s 3/8th Rule C Program
Picard’s Method C Program
Regula Falsi Method C Program
Bisection Method Algorithm and Flowchart
Simpson’s 1/3rd Rule C Program
Trapezoidal Rule C Program

2 thoughts on “Weddle’s Rule C Program

  1. Nakul agarwal

    Whats the relation between Simpson’s 3/8 rule and weddle’s rule?

    Reply

Let's Discuss