Beruflich Dokumente
Kultur Dokumente
ROLL NUMBER
1) GOURANGA SARKAR
1) 000810301007
2) 000810301013
3) BAPPA SAHA
3) 000810301018
4) 000810301025
C0NTENTS
SET 1
SET 2
SET 3
SET 4
SET 5
SET 5
SET 6
SET 6
SET 7
PROBLEM NO.3
PROBLEM NO.7
PROBLEM NO.3
PROBLEM NO.3
PROBLEM NO.3
PROBLEM NO.9
PROBLEM NO.3
PROBLEM NO.9
PROBLEM NO.1
GROUP NO.3
CLASS: B.CH.E 2nd YEAR
SECTION: A - 1
Step 6: term=term/x.
Step 7: sum=sum+term,x++, a--.
PROGRAM:
// program to calculate sum of series //
# include<stdio.h>
# include<conio.h>
# include<math.h>
# define eps 1.0e-05
void main(void)
{
int a;
int x=1;
float term=1;
float sum=0;
clrscr();
printf("\n\n\n enter the value of term at which term sum will be needed a:");
scanf("%d" ,&a);
} while(a>0)
{
term=term/x;
sum=sum+term;
x++;
a--;
}
printf("\n\n\n sum of series upto following term is =%f",sum);
getch();
}
SAMPLE INPUT:
1) 2
2) 3
3) 4
4) 5
5) 6
3) 1.7083334
4) 1.7166667
5) 1.7180556
.
REMARKS: From this program we can easily calcute the sum of this series for upto various
terms.
ALGORITHM:
Step 1: define the equestion f(x)=0.
Step 2: read the diserid accuracy say,epsilon(e) & maxit.
Step 3: do
{ Enter the initial approximation say, a & b.
} while(f(a)*f(b)>0);
Step 4: k < - 0.
Step 5: do
{ x < - (a+b)/2
if(f(a)*f(b)<0), b < - x
else
a < - x, k+=1;
} while (fabs(b-a)>e & k < maxit);
Step 6: if (k<maxit)
Root < - x, No. of iteration < - k.
else
iteration does not converge.
Step 7: end the algorithm.
PROGRAM:
//program for bisection method//
#include <stdio.h>
#include<conio.h>
#include <math.h>
main()
{
float f(float);
float x0,x1,x2,f0,f1,f2,R=0.0821,T=417,P=76;
int i=1,j;
printf("\n the volume of ideal gas is =%f",(R*T)/8*P);
printf("Give the guess values x0,x1 (x0<x1)\n");
scanf("%f%f", &x0, &x1);
f0=f(x0);
f1=f(x1);
if((f0/f1)>0)
printf("Guess values unsuitable");
if((f0/f1)<0)
{
printf("Upto which decimal point you want the root?\n");
scanf("%d",&j);
while((x1-x0)>pow(10,(-1*j)))
{
x2=(x0+x1)/2.0;
f2=f(x2);
printf("%d %f %f %f %f %f %f\n",i,x0,x1,x2,f0,f1,f2);
if((f2/f0)>0)
{
x0=x2;
f0=f2;
}
else
{
x1=x2;
f1=f2;
}
i++;
}
}
printf("\n\nThe root of the eqn converges to %f.",x2);
}
float f(float x)
{
float f;
f=(pow(x,3)-0.257*x*x+0.43*x-0.024);
return(f);
SAMPLE
INPUT
0.0001
SAMPLE
OUTPUT
1
2
REMARKS
-0.500000
-0.500000
1.000000
0.250000
0.250000
-0.428250
-0.125000
-0.428250
22
-0.500000
-0.499999
23
-0.500000
-0.500000
-0.500000
1.149000
0.000000
-0.428250
0.000000
-0.500000 -0.428250
0.000000
ALGORITHM:
PROGRAM:
// program for gauss-siedel method //
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define n 3
void main ( )
{
int i,j,p,k,maxit;
float x[n],a[n][n],sum=0,px[n],e=pow(e,-0.5),b[n];
clrscr( );
printf("\n enter the number of equations say n:");
scanf("%d",&p);
printf("\enter the maximum iteration number say maxit:");
scanf("%d", & maxit);
printf("\n enter the right hand side constant say b:");
for(i=0;i<n;i++)
{
printf("\n b[%d]=\t",b[i]);
scanf("%f",&b[i]);
}
printf("\n enter the coefficient matrix(row wise)say a[][]:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\n a[%d][%d]=\t",i,j);
scanf("%f",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
x[i]=0.0;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(j!=i){
sum=sum+a[i][j]*x[j];}
}
}
for(i=0;i<n;i++)
{
for(k=0;k<maxit;k++)
{
px[i]=x[i];
x[i]=(b[i]-(sum))/a[i][i];
if(fabs(x[i]-px[i])<e)
printf("\n the solution x[%d]=%f",i,x[i]);
}
}
getch();
}
SAMPLE
b[ 0 ] =
b[ 0 ] =
CORRESPONDING
a[ 0 ][ 0 ]
10
a[ 0 ][ 1 ]
-1
a[ 0 ][ 2 ]
a[ 1 ][ 0 ]
a[ 1 ][ 1 ]
10
a[ 1 ][ 2 ]
-1
a[ 2 ][ 0 ]
a[ 2 ][ 1 ]
a[ 2 ][ 2 ]
20
SAMPLE
OUTPUT :
the solution x[ 0 ]
0.400000
the solution x[ 1 ]
0.300000
the solution x[ 2 ]
= 0.350000
REMARKS: this approximate value is very close to the actual mathematical value.
ALGORITHM:
PROGRAM:
// program for lagrangian formula //
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[50],y[50],sum=0.0,product,z;
int n,i,j,k,X,Y;
clrscr();
printf("\n enter the total terms:");
scanf("%d",&x);
printf("\n \t\t--:enter the table:--");
printf("\n X:");
scanf("%d",&X);
printf("\n Y:");
scanf("%d",&Y);
for(i=0;i<n;i++)
scanf("%f",&x[i]);
for(i=0;i<n;i++)
scanf("\n%f",&y[i]);
printf("\n enter the point at which you want to interpolate:");
scanf("%f",&z);
for(k=0;k<n;k++);
{
product=1.0;
for(j=0;j<n;j++)
{
if(j!=k)
{
product=product*((z-x[i])/(x[k]-x[j]));
}
}
sum=sum+(y[k]*product);
printf("\n \t sum=%f",sum);
}
printf("\n interpolation at(x=%f)=%y",z,sum);
getch();
}
SAMPLE INPUT:
enter the total terms :
--:enter the table
x:
y:
enter the point at which you want to inter polate:
SAMPLE OUTPUT:
sum=
interpolation at (x=)=
PROGRAM:
// program for simson's rule//
#include<stdio.h>
#include<conio.h>
#include<math.h>
else
sum2+=f(a+j*h);
}
i=(h/3)*(ends+(4*sum2)+(2*sum1));
printf("\n required integral(i)=%f",i);
}
else
{
printf("\n no need for calculations");
}
getch();
}
SAMPLE INPUT:
Enter the limits of integration :
Lower limit (a) = 0
Upper limit (b) = 6
Enter the no.of subinterval by which the interval [a,b] to be devided: 2
SAMPLE OUTPUT:
Required integral (i) =38.700001
ALGORITHM:
Step 1: Difine f(t,y) [=RHS of ODE dy/dx= f(t,y)
Step 2: Read t0,y0,h [initial value of t,y & step size h no of t]
Step 3: Read tp [value of t at which y required]
Step 4: n=( tp-t)/h + 0.5 [n= number of step size]
Step 5: For I < - 1 to n
Step 6: K1 < - f(t0,y0)
Step 7: K2 < - f(t0 +1/2*h, y0 + 1/2*K1*h)
Step 8: K3 < - f(t0 +1/2*h, y0 + 1/2*K2*h)
Step 9: K4 < - f(t0 + 1/2*h,y0 +1/2* K3*h)
Step 10: t0 < - t0 + h
Step 11: K < - h/6*(K1 + 2*K2 + 2*K3 + 1/2*K3*h)
Step 12: yi < - yi + K
Step 13: Write I,ti,yi
Step 14: next i /(repeat)
Step 15: end the algorithm.
PROGRAM (1);
//program for range kutta//
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int i,n;
float p,t,y,xp,h,m11,m12,m21,m22,m13,m23,m14,m24;
float func(float,float,float);
printf("enter the base year and pop.\n");
scanf("%f%f",&t,&y);
printf("\n enter the year at which pop. req.:");
scanf("%f",&xp);
printf("\n enter the step size,h:");
scanf("%f",&h);
n=(int)((xp-t)/h+0.5);
for(i=1;i<=n;i++)
{
m11=func(p,t,y);
m21=func(p,t,y);
m12=func(p+0.5*h,t+0.5*m11,y+0.5*m21);
m22=func(p+0.5*h,t+0.5*m11,y+0.5*m21);
m13=func(p+0.5*h,t+0.5*m12,y+0.5*m22);
m23=func(p+0.5*h,t+0.5*m12,y+0.5*m22);
m14=func(p+h,t+m13,y+m23);
m24=func(p+h,t+m13,y+m23);
t=t+(m11+2.0*m12+2.0*m13+m14)/6.0;
y=y+(m21+2.0*m22+2.0*m23+m24)/6.0;
printf("%5d%15.6f%15.6f\n",i,t,y);
}
printf("\n value of pop.at req. year=%f is %f\n ",t,y);
}
float func(float p,float t,float y)
{
float f;
f=(4.25713*pow(10,-12)*pow(y,2.010101));
return(f);
}
SAMPLE
INPUT
1841
SAMPLE
OUTPUT
1
REMARKS
:
1840.000000
0.200000
PROGRAM (2):
//program for range kutta//
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int i,n;
float t,y,xp,h,m1,m2,m3,m4;
float func(float,float);
printf("enter the base year and pop.\n");
scanf("%f%f",&t,&y);
printf("\n enter the year at which pop. req.:");
scanf("%f",&xp);
printf("\n enter the step size,h:");
scanf("%f",&h);
n=(int)((xp-t)/h+0.5);
for(i=1;i<=n;i++)
{
m1=func(t,y);
m2=func(t+0.5*h,y+0.5*m1*h);
m3=func(t+0.5*h,y+0.5*m2*h);
m4=func(t+h,y+m3*h);
t=t+h;
y=y+(m1+2.0*m2+2.0*m3+m4)*h/6.0;
printf("%5d%15.6f%15.6f\n",i,t,y);
}
printf("\n value of pop.at req. year=%f is %f\n ",t,y);
}
float func(float t,float y)
{
float f;
f=(4.25713*pow(10,-12)*pow(y,2.010101));
return(f);
}
SAMPLE
INPUT
:
ENTER THE BASE YEAR AND POPULATION 1840
0.2
1841
SAMPLE
OUTPUT
1
REMARKS
:
1840.000000
0.200000
PROGRAM (1):
//program for 4th order ranga kutta//
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int i,n;
float t,y1,y2,xp,h,m11,m12,m21,m22,m13,m23,m14,m24;
float func1(float,float,float);
float func2(float,float,float);
printf("enter the initial values of t,y1,y2 \n");
scanf("%f%f%f",&t,&y1,&y2);
printf("\n enter the time at which y1 and y2 are req.:");
scanf("%f",&xp);
printf("\n enter the step size,h:");
scanf("%f",&h);
n=(int)((xp-t)/h+0.5);
for(i=1;i<=n;i++)
{
m11=h*func1(t,y1,y2);
m21=h*func2(t,y1,y2);
m12=h*func1(t+0.5*h,y1+0.5*m11,y2+0.5*m21);
m22=h*func2(t+0.5*h,y1+0.5*m11,y2+0.5*m21);
m13=h*func1(t+0.5*h,y1+0.5*m12,y2+0.5*m22);
m23=h*func2(t+0.5*h,y1+0.5*m12,y2+0.5*m22);
m14=h*func1(t+h,y1+m13,y2+m23);
m24=h*func2(t+h,y1+m13,y2+m23);
t=t+h;
y1=y1+(m11+2.0*m12+2.0*m13+m14)/6.0;
y2=y2+(m21+2.0*m22+2.0*m23+m24)/6.0;
printf("%5d%15.6f%15.6f%15.6f\n",i,t,y1,y2);
}
printf("\n values of y1 and y2 at t=%f is %f and %f",t,y1,y2);
}
float func1(float t,float y1,float y2)
{
float f1;
f1=(-0.2*y1+0.2*y2);
return(f1);
}
float func2(float t,float y1, float y2)
{
float f2;
f2=(10.0*y1-(60.0+0.125*t)*y2+0.124*t);
return(f2);
}
SAMPLE INPUT :
ENTER THE INITIAL VALUES OF t , y1 , y2
0
0
0
ENTER THE TIME AT WHICH Y1 AND Y2 ARE REQUIRED :2
VALUES OF y1 AND y2 AT
0.000728
AND
0.004201
t = 2.000037
IS
PROGRAM (2):
//program for 4th order multidimentional range kutta//
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int i,n;
float
t,y1,y2,y3,y4,xp,h,m11,m12,m21,m22,m13,m23,m14,m24,m31,m32,m33,m34,m41,m42,m43,
m44;
float func1(float,float,float,float,float);
float func2(float,float,float,float,float);
float func3(float,float,float,float,float);
float func4(float,float,float,float,float);
for(i=1;i<=n;i++)
{
m11=h*func1(t,y1,y2,y3,y4);
m21=h*func2(t,y1,y2,y3,y4);
m31=h*func3(t,y1,y2,y3,y4);
m41=h*func4(t,y1,y2,y3,y4);
m12=h*func1(t+0.5*h,y1+0.5*m11,y2+0.5*m21,y3+0.5*m31,y4+0.5*m41);
m22=h*func2(t+0.5*h,y1+0.5*m11,y2+0.5*m21,y3+0.5*m31,y4+0.5*m41);
m32=h*func3(t+0.5*h,y1+0.5*m11,y2+0.5*m21,y3+0.5*m31,y4+0.5*m41);
m42=h*func4(t+0.5*h,y1+0.5*m11,y2+0.5*m21,y3+0.5*m31,y4+0.5*m41);
m13=h*func1(t+0.5*h,y1+0.5*m12,y2+0.5*m22,y3+0.5*m32,y4+0.5*m42);
m23=h*func2(t+0.5*h,y1+0.5*m12,y2+0.5*m22,y3+0.5*m32,y4+0.5*m42);
m33=h*func3(t+0.5*h,y1+0.5*m12,y2+0.5*m22,y3+0.5*m32,y4+0.5*m42);
m43=h*func4(t+0.5*h,y1+0.5*m12,y2+0.5*m22,y3+0.5*m32,y4+0.5*m42);
m14=h*func1(t+h,y1+m13,y2+m23,y3+m33,y4+m43);
m24=h*func2(t+h,y1+m13,y2+m23,y3+m33,y4+m43);
m34=h*func3(t+h,y1+m13,y2+m23,y3+m33,y4+m43);
m44=h*func4(t+h,y1+m13,y2+m23,y3+m33,y4+m43);
t=t+h;
y1=y1+(m11+2.0*m12+2.0*m13+m14)/6.0;
y2=y2+(m21+2.0*m22+2.0*m23+m24)/6.0;
y3=y3+(m31+2.0*m32+2.0*m33+m34)/6.0;
y4=y4+(m41+0.2*m42+2.0*m43+m44)/6.0;
printf("%5d%15.6f%15.6f%15.6f%15.6f%15.6f\n",i,t,y1,y2,y3,y4);
}
printf("\n values of y1,y2,y3 and y4 at t=%f are %f,%f,%f and %f",t,y1,y2,y3,y4);
}
float func1(float t,float y1,float y2,float y3,float y4)
{
float f1;
f1=1.3*(y2-y1)+1.04*pow(10,4)*(6*pow(10,-4)*pow(2.73,(20.7(15*pow(10,3))/y1)))*y2;
return(f1);
}
float func2(float t,float y1, float y2,float y3,float y4)
{
float f2;
f2=1.88*pow(10,3)*(y4-(1.0+(6*pow(10,-4)*pow(2.73,(20.7-(15*pow(10,3))/y1)))));
return(f2);
}
float func3(float t,float y1,float y2,float y3,float y4)
{
float f3;
f3=(1752+266.1*y2-269.3*y3);
return(f3);
}
SAMPLE INPUT
VALUES OF y1 AND y2 AT
IS
0.000728
AND
0.004201
t =
2.000037
#include <math.h>
#define f(x,y) (x*x+x*y+y*y-7)
#define g(x,y) (pow(x,3)+pow(y,3)-9)
main()
{
int i,j,k,n;
double x_0=1.5,y_0=0.5,det_J,b[2][1],a[2][1],x[2][1];
b[0][0]=x_0;
b[1][0]=y_0;
x[0][0]=x_0;
x[1][0]=y_0;
for(k=0;k<10;k++)
{
a[0][0]=((3*x[1][0]*x[1][0])*((x[0][0]*x[0][0])+(x[0][0]*x[1][0])+(x[1][0]*x[1][0])-7))+(((x[0][0]+2*x[1][0]))*(pow(x[0][0],3)+pow(x[1][0],3)-9));
a[1][0]=(-3*x[0][0]*x[0][0])*((x[0][0]*x[0][0])+(x[0][0]*x[1][0])+(x[1][0]*x[1][0])7)+((2*x[0][0]+x[1][0])*(pow(x[0][0],3)+pow(x[1][0],3)-9));
det_J=((3*x[1][0]*x[1][0])*(2*x[0][0]+x[1][0]))-((3*x[0][0]*x[0][0])*(x[0][0]+2*x[1][0]));
x[0][0]=b[0][0]-(a[0][0]/det_J);
x[1][0]=b[1][0]-(a[1][0]/det_J);
printf("\nFor the %d iteration current value: %f %f",k+1,x[0][0],x[1][0]);
b[0][0]=x[0][0];
b[1][0]=x[1][0];
getch();
return 0;
}
SAMPLE OUTPUT:
for the 1 iteration current value:2.267544 0.925439