All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Wednesday 22 April 2015

Simpson's 3/8th rule to find Integration of Difference Table

#include<iostream>
using namespace std;
int main()
{
    int i,n;
    float x[10],y[10],h,sum;

    cout<<"Enter no of values in table: ";
    cin>>n;
    cout<<"Enter X & corresponding Y:\n";
    for(i=0;i<n;i++)
        cin>>x[i]>>y[i];

Simpson's 3/8th Rule to find Integration of Function

#include<iostream>
#include<math.h>

using namespace std;
float f(float x)
{
    return 1/(1+x*x); //Function f(x)
}
int main()
{
    int i,n;
    float x0,xn,h,sum;
    cout<<"Enter no of Intervals: ";

Simpson's 1/3rd Rule to find Integration of Difference Table.

#include<iostream>
using namespace std;
int main()
{
    int i,j,k,n;
    float x[10],y[10],sum,h;
    cout<<"Enter no of Values in table: ";
    cin>>n;
    cout<<"Enter X and corresponding Y\n";

Simpson's 1/3rd Rule to find Integration of a Function

#include<iostream>
#include<math.h>

using namespace std;
float f(float x)
{
    return 1/(1+x*x);
}
int main()
{
    int i,n;
    float x0,xn,h,sum;
    cout<<"Enter no of Intervals: ";

Trapezoidal Rule to find Integration of Diff.-Table

#include<iostream>
using namespace std;
int main()
{
    int i,j,k,n;
    float x[10],y[10],sum,h;
    cout<<"Enter no of Values in table: ";
    cin>>n;
    cout<<"Enter X and corresponding Y\n";
    for(i=0;i<n;i++)

Trapezoidal Rule to find integration of a Function

#include<iostream>
#include<math.h>

using namespace std;
float f(float x)
{
    //return exp(x*x); // function f(x)
    return (x*x)/(1+x*x*x); //Function f(x)
    //return exp(-x*x);
}
int main()
{
    int i,n;
    float x0,xn,h,sum;
    cout<<"Enter no of Intervals: ";

Thursday 9 April 2015

Interpolation using Guass Forward Interpolation Formula

#include<iostream>
#define N 4

using namespace std;
int main()
{
    float ax[10],ay[10],dtab[10][N+1],x,h,p,y;
    float y0,y1,y2,y3,y4;
    int i,j,k,n;
    cout<<"Enter Value of n: ";
    cin>>n;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            dtab[i][j]=0.0;
           
    cout<<"Enter Value for X and Y respectively\n";
    cout<<"X   Y\n";
    for(i=0;i<n;i++)
        cin>>ax[i]>>ay[i];
       
    cout<<"Enter the value of X for which Y is Required: ";
    cin>>x;
    h=ax[1]-ax[0];
   
    for(i=0;i<=n-1;i++)
        dtab[i][1]=ay[i+1]-ay[i];
    for(j=2;j<=N;j++)
    {
        for(i=0;i<n-j;i++)
            dtab[i][j]=dtab[i+1][j-1]-dtab[i][j-1];
    }
    for(i=0;x>ax[i];i++);
        i--;
    p=(x-ax[i])/h;
    y0=ay[i];
    y1=p*dtab[i][1];
    y2=p*(p-1)*dtab[i-1][2]/2;
    y3=(p+1)*p*(p-1)*dtab[i-1][3]/6;
    y4=(p+1)*p*(p-1)*(p-2)*dtab[i-2][4]/24;
    y=y0+y1+y2+y3+y4;
    cout<<"\nFor X="<<x<<" Y="<<y;
    return 0;
}

Interpolation using Newton's Divided Difference Formula (For Unequal Intervals)


#include<iostream>
using namespace std;
int main()
{
int x[10],y[10],p[10];
int i,j=1,k,n,t,y1,f=0;
cout<<"Enter No of Values in table: ";
cin>>n;
cout<<"Enter X and Corresponding Y\n";
cout<<"X   Y\n";
for(i=1;i<=n;i++)
cin>>x[i]>>y[i];
y1=y[1];
cout<<"Enter X for which f(x) is to be calculated: ";
cin>>k;

Wednesday 8 April 2015

Interpolation using Lagrange's Interpolation Formula (For Unequal Intervals)

#include<iostream>
using namespace std;
int main()
{
float x[10],y[10],x1,y1=0.0;
int i,j,n;
cout<<"Enter No of terms in table: ";
cin>>n;
cout<<"Enter X and Corresponding Y\n";
cout<<"X   Y\n";
for(i=0;i<n;i++)
cin>>x[i]>>y[i];
cout<<"Enter the X for which Y to be Found: ";
cin>>x1;

Interpolation using Newton's Backward Interpolation Formula

#include<iostream>
#define N 4
using namespace std;
int main()
{
float ax[10],ay[10],dtab[10][N+1],x,h,p,y;
int i,j,k,n;
cout<<"Enter Value of n: ";
cin>>n;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
dtab[i][j]=0.0;

Interpolation using Newton's Forward Difference Formula

#include<iostream>
#define N 4
using namespace std;
int main()
{
float ax[10],ay[10],dtab[10][N+1],x,h,p,y;
int i,j,k,n;
cout<<"Enter Value of n: ";
cin>>n;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
dtab[i][j]=0.0;

Wednesday 18 March 2015

Power Method of finding Eigen Value & Eigen Vector



#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    float a[10][10],x[10],c[10],ev=0,t;
    int i,j,n;
    cout<<"Enter the order of matrix= ";
    cin>>n;
    cout<<"Enter the Coefficients of matrix row-wise\n";

Tuesday 17 March 2015

Solution of System of Linear Equation by Gauss Seidal Method

#include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;
int main()
{
    float a[20][20],x[20],e;
    int i,j,k,n,count=0;
    cout<<"Enter Order of equation: ";
    cin>>n;
    for(i=0;i<n;i++)
        x[i]=0;
    cout<<"Enter Coefficients of equation row-wise:\n";

Soving System of Linear Eq. By LU Factorization Method

#include<iostream>
using namespace std;
int main()
{
    int i,j,k,n,p;
    float a[10][10],l[10][10]={0},u[10][10]={0},b[10],z[10]={0},x[10]={0};
    cout<<"Enter order of matrix: ";
    cin>>n;
    cout<<"Enter the coefficients of matrix A\n";
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            cin>>a[i][j];
    }

Saturday 7 March 2015

Solution of System of Linear Equations by Gauss-Jacobi's Method

#include<iostream>
#include<math.h>
#include<iomanip>
#define err 0.0001

using namespace std;
int main()
{
    float a[20][20],x[20],e;
    int i,j,k,n,max;
    cout<<"Enter Order of equation: ";
    cin>>n;
    for(i=0;i<n;i++)
        x[i]=0;
    cout<<"Enter Coefficients of equation row-wise:\n";

Solution of System of Linear Equations by Gauss Jardon Method


#include<iostream>
#include<iomanip>

using namespace std;
int main()
{
    int i,j,k,n;
    float a[10][10],x[10];
    cout<<"Enter Order of Equation: ";
    cin>>n;
    cout<<"Enter Coefficients of Equation Row-wise\n";

Solution of System of Linear Equations by Gauss Elimination Method

#include<iostream>
#include<iomanip>

using namespace std;
int main()
{
    int i,j,k,n;
    float a[10][10],x[10];
    cout<<"Enter Order of Equation: ";
    cin>>n;
    cout<<"Enter Coefficients of Equation Row-wise\n";

Friday 13 February 2015

Newton-Raphson's Method

#include<iostream>
#include<math.h>
#include<iomanip>
#define err 0.0001
//Correction upto three places
using namespace std;
float f(float x)
{
return pow(x,4)-x-9;
//Function f(x)
}
float df(float x)
{
return 4*pow(x,3)-1;
//Diffirenciation of f(x)
}

Iteration Method of Solving Transcidental Equations

#include<iostream>
#include<math.h>
#define err 0.0001
//Correction upto three Places
using namespace std;
float iterative(float x)
{
return pow((x+9),0.25); //Function G(x)=0
}
float f(float x)
{
return x*x*x*x-x-9; //Function f(x)=0
}
int main()
{
int i=1;
float x0,x1;
cout<<"Enter the first approximation ";
cin>>x0;

Secant Method of Solving Transcidental Equation

#include<iostream>
#include<math.h>
#include<iomanip>
#define err 0.0001
//Correction upto three places
using namespace std;
float f(float x)
{
return x*x*x-2*x-5; //Place your Function here
}
float secant(float x0,float x1)
{
return x1-((x1-x0)/(f(x1)-f(x0))*f(x1));
}
int main()
{
int i=2;
float x0,x1,x2,x3;
cout<<"Enter two initial approximate roots x0,x1 : ";
cin>>x0>>x1;

Method Of false Position (Regula-Falsi method)

#include<iostream>
#include<math.h>
#include<iomanip>
#define err 0.0001
//Correction upto three places
using namespace std;
float f(float x)
{
return cos(x)-x*exp(x); //Place your Function Here
}
float regula(float x0,float x1)
{
return x0-((x1-x0)/(f(x1)-f(x0))*f(x0));
}
int main()
{
int i=1,max;
float x0,x1,x2,x3;
cout<<"Enter two initial approximate roots x0,x1 : ";
cin>>x0>>x1;

Bisection Method of Solving Equation

#include<iostream>
#include<math.h>
#include<iomanip>
#define bisect(a,b) (a+b)/2
#define err 0.0001
//Correction upto three places
using namespace std;
float f(float x)
{
return pow(x,4)-x-9; //Put Your Function here
}
int main()
{
int i=1,max;
float x,x1,a,b;
cout<<"Enter two initial approximate roots a,b : ";
cin>>a>>b;