Professional Documents
Culture Documents
Minor Dev C++ Programs - 4 To 6
Minor Dev C++ Programs - 4 To 6
VIPUL GUPTA
2k8/EE/889
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{clrscr();
float a[5][5],b[5][5];
float x,y,z;
int i,j,p,q,r;
int max=0;
int n[4];
cout<<"enter coefficients of equation ax+by+cz=d \n";
for(i=1;i<4;i++)
{
cout<<"\nenter coefficients of "<< i <<"equation\n";
for(j=1;j<5;j++)
{ cin>>a[i][j];
// cout<<"\t";
}
cout<<"\n";
}
for(i=1;i<4;i++)
{ max=0;
for(j=1;j<4;j++)
{if (a[i][j]>max)
{max=a[i][j];
n[i]=j;
}
}
cout<<" max term in "<< i<<" equation is "<<max<<" at the position "<<n[i]<<"\n" ;
}
y=z=0;
for(int m=0;m<2000;m++)
{
for ( p=1;p<4;p++)
{ if(n[p]==1)
{ x=((a[p][4]-(z*a[p][3])-(y*a[p][2]))/a[p][1]);
for ( q=1;q<4;q++)
{ if(n[q]==2)
{
y=((a[q][4]-(x*a[q][1])-(z*a[q][3]))/a[q][2]);
for ( r=1;r<4;r++)
{ if(n[r]==3)
{
z=((a[r][4]-(x*a[r][1])-(y*a[r][2]))/a[r][3]);
}}}}}}}
cout<<"\n value of x : "<<x;
cout<<"\n value of y : "<<y;
cout<<"\n value of z :"<<z;
getch();
}
OUTPUT:
19/4/2011
5. EULERs METHOD
VIPUL GUPTA
2k8/EE/889
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
26/4/2011
6. SHOOTING METHOD
VIPUL GUPTA
2k8/EE/889
// Write a Program to solve a 2nd order Linear differential equation by SHOOTING METHOD
/* A Boundary Value Problem is given
d2y/d2x= 2y + 8x(9 x)
y(0) = 0 and y(9) = 0
*/
#include<iostream>
#include<conio.h>
#include<cmath>
using namespace std;
float y[4],z[4],fv=0,h=3,x;
int i,j;
float fdd(float x,float y)
{
float temp=2*y+8*x*(9-x);
return temp;
}
void solve(float d)
{
x=0;
z[0]=d;
for(i=1;i<4;i++)
{
y[i]=y[i-1]+z[i-1]*h;
z[i]=z[i-1]+fdd(x,y[i-1])*h;
x=x+h;
}
}
int main()
{
y[0]=0;
float l,m,q,k;
solve(4);
// Finding an interval in which Final value of function Lies
if(y[3]>fv)
{
for( i=1 , j=-1; ;i++,j--)
{
solve(i);
if(y[3]<=fv)
break;
solve(j);
if(y[3]<=fv)
break;
}
solve(i);
l=y[3];
solve(j);
m=y[3];
if(y[3]<=fv)
k=i;
else
k=j;
if(l<fv&&m<fv)
{
if(l>m)
k=i;
else
k=j;
}
}
else
{
for( i=1 , j=-1; ;i++,j--)
{
solve(i);
if(y[3]>=fv)
break;
solve(j);
if(y[3]>=fv)
break;
}
solve(i);
l=y[3];
solve(j);
m=y[3];
if(y[3]>=fv)
k=i;
else
k=j;
if(l>fv&&m>fv)
{
if(l>m)
k=j;
else
k=i;
}
}
solve(0);
l=y[3];
solve(k);
m=y[3];
q=fv;
// Interpolation
k=k+((k-0)/(m-l))*(q-m);
cout<<endl<<k;
solve(k);
cout<<"Final Value at "<<k<<" is "<<y[3]<<endl;
// Solution to equation
x=0;
for(i=0;i<4;i++)
{
cout<<"Value of function at "<<x<<" is "<<y[i]<<endl;
x= x+h;
}
system("pause");
}
/*
OUTPUT
-20.5714
Final Value at -20.5714 is -1.52588e-005
Value of function at 0 is 0
Value of function at 3 is -61.7143
Value of function at 6 is -123.429
Value of function at 9 is -1.52588e-005
Press any key to continue . . .
/*
Following GRAPH is obtained by solving above 2nd order Differential equation
0
-20
-40
-60
-80
-100
-120
-140