Ticker

6/recent/ticker-posts

CPNM LAB PROGRAM-14

 

14. Implement Gaussian quadrature for numerical integration .

           FLOW CHART :-

Algorithm:
Step – 1 : Start
Step – 2 : Declare p, q, r, a, b, k as float variables
Step – 3 : Enter limits a and b
Step – 4 : Assign p = (a + b) / 2
Step – 5 : Assign q = (b – a) / 2
Step – 6 : Assign Integral = q *(f(p + q / sqrt(3))+f(p-q/sqrt(3)))
Step – 7 : Print integral value
Step – 8 : Stop
Step – 1 : Call function float f(float x)
Step – 2 : return(x * x + 2 * x)

Program:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
float f(float x)
{
//return(exp(-x*x));
return(x * x + 2 * x);
}
main()
{
float p, q, a, b, Integral;
clrscr();
printf("Enter a and b limits \n");
scanf("%f,%f",&a,&b);
p = (a + b) / 2;
q = (b - a) / 2;
Integral = q *(f(p + q / sqrt(3))+f(p-q/sqrt(3)));
printf("Integral = %f\n", Integral);
getch();
return 0;
}

Output:
Enter a and b limits
2, 4
Integral = 30.666666

Post a Comment

0 Comments