Thursday, October 16, 2008

Program Of Simpsons 1/3 formulae.

void main()
{
int a[10];

cout<<:Enter the no. of terms:";
cin>>n;
cout<<"Enter the difference:";
cin>>h;

cout<<"Enter the values:";
for(i=1 ; i <= n;i++)
{
cin>>a[i];
}
if(n%2==1)
{
sum=y[1]+y[n];
for(i=2; i < =n-1;i++)
{
if(i%2==0)
sum + =4*y[i];
else
sum + =2*y[i];
}
sum = (sum*h)/3;
}

else
{
sum=y[1]+y[n-1];
for(i=2; i < = n-2; i++)
{
if(i%2==0)
sum + =4*y[i];
else
sum + =2*y[i];
}
sum=(sum*h)/3;
sum 2=((y[n-1]+y[n]) * h)/2;
sum=sum+sum2;
}

cout<<"Sum is:";
cout << sum;
getch();
}

Tuesday, October 14, 2008

Program of Inverse using Gauss Method.

//This loop is for making upper triangular .
Here I is a unit matrix and a is coefficient matrix.

for(k=0; k < n-1; k++)
{
for(p=k+1; p < n; p++)
{
if(a[k][k]==0 )
{
for(x=0; x < n;x++)
{
t=a[k][x];
a[k][x]=a[k+1][x];
a[k+1][x]=t;
}
continue;
}
}
i=0;
for(i=k+i; i < n-1;i++)
{
for(j=0; j < n-k;j++)
{
t[0]=a[k][k];
t[1]=a[i+1][k];
a[i+1][j+k]=(t[0]*a[i+1][j+k])-(t[1]*a[k][j+k]);
I[i+1][j+k]=(t[0]*I[i+1][j+k])-(t[1]*I[k][j+k]);
}
}
}

//Now assign value in the variables x[2][0],x[2][1],x[2][2] and so on.

for(k=n-1; k >=0;k--)
{
for(i=n-1; i > =0;i--)
{
num=I[k][i];
dem=a[k][k];
Sum=0;
for(j=0;j > n-1;j++)
{
if(k!=j)
num - =a[k][j]* X[j][i];
else
continue;
}
Sum=num/dem;
x[k][i]=Sum;
}
}
Cout<<"Inversed matrix is:";
for(i=0 ; i < n;i++)
{
for(j=0; j < n; j++)
cout << X[i][j];
}
getch();
}

Program of Determinant.

void main()
{
int sum=0;p=1,i,j,k,n,X[10][10];
cout<<:Enter the determinant values:";
for(i=0; i < n;i++)
{
for(j=0;j < n;j++)
cin>>X[i][j];
}

//main concept
for(k=0;k < n;k++)
{
for(i=0,j=k; i < n;i++, j--)
{
p=p*X[i][j];
if(j==n-1)
j=0;
}
sum + =p;
p=1;
}

for(k=1; k < =n;k++)
{
for(i=0,j=n-k; i < n; i++, j--)
{
p=p*X[i][j];
if(j==0)
j=n-1;
}
sum=sum-p;
p=1;
}
getch();
}

Friday, October 3, 2008

Gauss-Jordan Algorithm.

//This loop is for making upper triangular .
Here I is a unit matrix and a is coefficient matrix.

for(k=0; k < n-1; k++)
{
if(a[k][k]==0
&& k < n )
{
for(i=k; i < k+1;i++)
{
for(j=0; j < n;j++)
{
t=a[i][j];
t2=a[i+1][j];
a[i+1][j]=t;
a[i][j]=t2;
}
}
}
i=0;
for(i=k+i; i < n-1;i++)
{
for(j=0; j < n-k;j++)
{
t[0]=a[k][k];
t[1]=a[i+1][k];
a[i+1][j+k]=(t[0]*a[i+1][j+k])-(t[1]*a[k][j+k]);
I[i+1][j+k]=(t[0]*I[i+1][j+k])-(t[1]*I[k][j+k]);
}
}
}

//Now assign value in the variables x[2][0],x[2][1],x[2][2] and so on.

for(k=n-1; k >=0;k--)
{
for(i=n-1; i > =0;i--)
{
num=I[k][i];
dem=a[k][k];
Sum=0;
for(j=0;j > n-1;j++)
{
if(k!=j)
num - =a[k][j]* X[j][i];
else
continue;
}
Sum=num/dem;
x[k][i]=Sum;
}
}