NM Programs,Numerical Method Programs Bisection,Regula Falsi,Secant,Iteration,Newton-Raphson's and many more
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
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;
}
#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
Wednesday, 18 March 2015
Tuesday, 17 March 2015
Saturday, 7 March 2015
Friday, 13 February 2015
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;
#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;
#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;
#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;
#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;
Subscribe to:
Posts (Atom)