#include<iostream.h>
#include<conio.h>
float f1(float ,float,float);
float f2(float, float ,float);
int main()
{
int i;
C C++ CODE : Shooting method for solving boundary value problem
Working C C++ Source code program for Shooting method for solving boundary value problem
C C++ CODE : Simpsons 1/3 rule for integration
Working C C++ Source code program for Simpsons 1/3 rule for integration
/************** SIPMPSONS 1/3 RULE ***********************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
float funct(float a);
int main()
{
char choice='y';
float f,x,h,a,b,sum;
clrscr();
cout<<"a & b ? ";cin>>a>>b;
do
{
sum=0;
x=a;
cout<<"Enter value of h ? ";cin>>h;
while(x<b)
{
sum+=(funct(x)+4*funct(x+h)+funct(x+2*h));
x=x+2*h;
}
cout<<endl<<"The integration is: "<<sum*h/3<<endl;
cout<<endl<<"wanna continue (y/n) ? ";cin>>choice;
}while(choice=='y');
getch();
return 0;
}
float funct(float x)
{
return x*exp(x)-2; // sin takes arguments in radian........
}
C C++ CODE : Trapezoidal rule for integration
Working C C++ Source code program for Trapezoidal rule for integration
/************* TRAPEZOID FULE FOR INTEGRATION *****************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
float funct(float a);
int main()
{
char choice='y';
float f,x,h,a,b,sum;
clrscr();
cout<<"a & b ? ";cin>>a>>b;
do{
sum=0;
x=a;
cout<<"Enter value of h ? ";cin>>h;
while(x<b)
{
sum+=(funct(x)+funct(x+h));
x=x+h;
}
cout<<endl<<"The integration is: "<<sum*h/2<<endl;
cout<<endl<<"wanna continue (y/n) ? ";cin>>choice;
} while(choice=='y');
getch();
return 0;
}
float funct(float x)
{
return x*exp(x)-2; // sin takes arguments in radian........
}
C C++ CODE : Numerical integration for tabular data
Working C C++ Source code program for numerical integration - trapeziode and simpsons 1/3 method
/************************ INTEGRATION FOR TABULAR DATA *****************/
#include<iostream.h>
#include<conio.h>
int main()
{
int n,i;
float x[10],f[10],h,sum=0,a;
clrscr();
cout<<"No of datas ? ";cin>>n;
cout<<"Enter datas : ";
for(i=0;i<n;i++)
cin>>x[i]>>f[i];
for(i=0;i<n;i++)
{
if(i==0||i==n-1)
sum+=f[i];
else
sum+=2*f[i];
}
h=x[1]-x[0];
cout<<"The value using trapezoide: "<<h*sum/2;
a=x[0];
sum=0;
while((a-h)<x[n])
{
sum+=(f[a]+4*f[a+h]+f[a+2*h]);
a+=2*h;
}
cout<<"\nThe value using simpsons 1/3 is : "<<h*sum/3;
getch();
return 0;
}
C C++ code : power method - numerical method to find eigen value and vector
Working C C++ Source code program for finding eigen value and eigen vector by power method
/************* Eigen value and eigen vector by Power method ***********/
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
float a[10][10],x[10],c[10],d=0,temp;
int n,i,j;
C C++ CODE: Gauss Jordon elimination method to solving linear equations
Working C C++ Source code program for Gauss Jordon elimination method to solving linear equations
/*************** Gauss Jordan method ********************/
#include<iostream.h>
#include<conio.h>
int main()
{
int i,j,k,n;
float a[10][10],d;
clrscr();
cout<<"No of equations ? ";cin>>n;
cout<<"Read all coefficients of matrix with b matrix too "<<endl;
for(i=1;i<=n;i++) // read nxn matrix - cofficients
for(j=1;j<=n+1;j++)
cin>>a[i][j];
/************** partial pivoting **************/
for(i=n;i>1;i--)
{
if(a[i-1][1]<a[i][1])
for(j=1;j<=n+1;j++)
{
d=a[i][j];
a[i][j]=a[i-1][j];
a[i-1][j]=d;
}
}
cout<<"pivoted output: "<<endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
/********** reducing to diagonal matrix ***********/
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
if(j!=i)
{
d=a[j][i]/a[i][i];
for(k=1;k<=n+1;k++)
a[j][k]-=a[i][k]*d;
}
}
/************** reducing to unit matrix *************/
for(i=1;i<=n;i++)
{
d=a[i][i];
for(j=1;j<=n+1;j++)
a[i][j]=a[i][j]/d;
}
cout<<"your solutions: "<<endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
getch();
return 0;
}
C C++ CODE : Gauss jordan method for finding inverse matrix
Working C C++ Source code program for Gauss jordan method for finding inverse matrix
/*************** Gauss Jordan method for inverse matrix ********************/
#include<iostream.h>
#include<conio.h>
int main()
{
int i,j,k,n;
float a[10][10]={0},d;
clrscr();
C C++ CODE : LU Decomposition for solving linear equations
Working C C++ Source code program for LU Decomposition for solving linear equations
/************** LU Decomposition for solving linear equations ***********/
#include<iostream.h>
#include<conio.h>
int main()
{
int n,i,k,j,p;
float a[10][10],l[10][10]={0},u[10][10]={0},sum,b[10],z[10]={0},x[10]={0};
clrscr();
cout<<"Enter the order of matrix ! ";
cin>>n;
C C++ CODE : Gauss elimination for solving linear equations
Working C C++ Source code program for Gauss elimination for solving linear equations
/************* Gauss elimination for solving linear equations *************/
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,i,j,k,temp;
float a[10][10],c,d[10]={0};
clrscr();
cout<<"No of equation ? ";
cin>>n;
C C++ CODE : least square fitting regression
Working C C++ Source code program for least square fitting regression
/*************** least square fitting ******************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,i,j;
float a,a0,a1,x[10],f[10],sumx=0,sumy=0,sumxy=0,sumx2=0;
clrscr();
cout<<"Enter no of sample points ? ";cin>>n;
Subscribe to:
Posts
(
Atom
)