write a program to integrate a function using Gauss's Quadrature Formula in c++.
write a program to integrate a function using Gauss's Quadrature Formula in c++.
CODE:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
float g(float y)
{ return(y*y)+(8.0*y)+15;
}
void main()
{
clrscr();
int i,n;
float r[10],y[10],sum,a,b,integral;
cout<<"enter the value of n for no. of point=";
cin>>n;
cout<<"enter the first interval a =";
cin>>a;
cout<<"enter the second interval b=";
cin>>b;
for(i=1;i<=n;i++)
{
cout<<"enter the value of R["<<"]=";
cin>>r[i];
cout<<"enter the value of y["<<"]=";
cin>>y[i];
}
sum=0;
for(i=1;i<=n;i++)
{sum=sum+(r[i]*g(y[i]));
}
integral=((b-a)/2.0)*sum;
cout.setf(ios::showpoint);
cout<<setprecision(4);
cout<<"vale of the integral="<<integral;
getch();
}
OUTPUT:
Comments
Post a Comment