4th Sem. Computational Techniuqe

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 14

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)

JMIT

List of Experiments

Doc. No: ECE/MAT-206E


Rev. No. : 00
Page No 1 of 1

Subject Name: Computational Techniques


Sr. No.
1.

Work Instruction Sheet No. Aim of Experiment


ECE/ MAT-206E /WI-421 Numerical solution to an differential equation using the RangeKutta method.

2.

ECE/ MAT-206E /WI-422

Numerical solution to the integral equation using

ECE/ MAT-206E /WI-423

Simpson rule.
Solution to a non linear equation in single variable

4.

ECE/ MAT-206E /WI-424

using the method of Regular Falsi.


Solution to a system of simultaneous algebraic

5.

ECE/ MAT-206E /WI-425

equations using the Gauss-Seidel iterative method.


Numerical solution to an differential equation using

6.

ECE/ MAT-206E /WI-426

Eulers method.
Solution to a non linear equation in single variable

ECE/ MAT-206E /WI-427

using the method of successive Bisection.


Solution to a non linear equation in single variable

8.

ECE/ MAT-206E /WI-428

using the method of Newton raphons.


Numerical solution to an differential equation using

9.

ECE/ MAT-206E /WI-429

Predictor Corrector method.


Solution to a non linear equation in single variable

10.

ECE/ MAT-206E /WI-430

using the method of Newton Raphons.


Solution to a system of simultaneous algebraic

3.

7.

11.

ECE/ MAT-206E /WI-431

equations using the Gaussian elimination procedure.


Solution to a non linear equation in single variable
using the Secant .

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Issued By:

Work Instructions

Doc. No: ECE/ MAT-206E /WI-421


Rev. No. : 00
Page No. 1 of 1

Approved By:

Date of Issue:
02.02.09

Aim of Experiment: - Numerical solution to an differential equation using the RangeKutta method.
#include<stdio.h>
float f(float x,float y);
{
return x+y*y;
}
main()
{
float x0,y0,h,xn,x,y,k1,k2,k3,k4,k;
printf("Enter the value of x0,y0,h,xn\n");
scanf("%f%f%f%f",&x0,&y0,&h,&xn);
x=x0;
y=y0;
while(1)
{
if (x==xn)
break;
k1=h*f(x,y);
k2=h*f(x+h/2,y+k1/2);
k3=h*f(x+h/2,y+k2/2);
k4=h*f(x+h,y+k3);
k=(k1+(k2+k3)*2+k4)/6;
x+=h;
y+=k;
printf("when x= %8.4f""y=%8.4f\n",x,y);
}
}

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-422


Rev. No. : 00
Page No. 1 of 1

Aim of Experiment: - Numerical solution to the integral equation using Simpson rule.
#include<stdio.h>
float y(float x)
{
return 1/(1+x*x);
}
float x0,h,s,xn;
int i,n;
printf("Enter the x0,xn,,no. of subintervals");
scanf("%f%f%d",&x0,&xn,&n);
h=(xn-x0)/n;
s=y(x0)+y(xn)+4*y(x0+h);
for(i=3; i<=n-2; i+=2)
s+=4*y(x0+i*h)+2+y(x0+(i-1)*h);
printf("value of integral is %6.4f\n"(h/3)*s);
}

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-423


Rev. No. : 00
Page No. 1 of 2

Aim of Experiment: - Solution to a non linear equation in single variable using the method of
Regular Falsi.
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(x*x*x - (4*x)-9);
}
void false (float *x,float a, float b, int *itr)
{
*x =((b-a)*f(a)/(f(a)-f(b)))+a ;
++(*itr);
printf("\n iteration number = %3d, value of x = %7.5f",*itr,*x);
}
main()
{
int itr = 0,mitr;
float a,b,x,y,merr;
printf("enter the value of a,b""allowed error,maximum iterations \n");
scanf("%f%f%f%d",&a,&b,&merr,&mitr);
if (f(a)*f(b)>0)
{
printf("root doesnot lie in a and b");
return(0);
}
false (&x,a,b,&itr);
do{
if(f(x)*f(a)<0)
b=x;
else
a=x;
false(&y,a,b,&itr);
if (fabs(y-x)<merr)
{
printf("\nafter %d iterations,root=%f \n",itr,y);
Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-423


Rev. No. : 00
Page No. 2 of 2

return(0);
}
x=y;
}
while(itr<mitr);
printf("solution does not converge\n");
printf("iterations not sufficient");
return (1);
}

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-424


Rev. No. : 00
Page No. 1 of 1

Aim of Experiment: - Solution to a system of simultaneous algebraic equations using the


Gauss-Seidel iterative method.
#includse<stdio.h>
#include<math.h>
#define N 4
main()
{
float a[N][N+1],x[N],aerr,maxerr,t,s,err;
int i,j,itr,maxitr;
for(i=0;i<N;i++)
x[i]=0;
printf("enter the elements of the augmented matrix rowwise\n");
for(i=0;i<N;i++)
for(j=0;j<N+1;j++)
scanf("%f",&a[i][j]);
printf("enter the allowed errer & max iterations\n");
scanf("%f%d",&aerr,&maxitr);
printf("iteration x[1] x[2]""x[3]\n");
for(itr=1; itr<=maxitr;itr++)
{
maxerr=0;
for(i=0;i<N;i++)
{
s=0;
for(j=0;j<N;j++)
if(j!=i)
s+=a[pi][j]*x[j];
t=(a[i][N]-s)/a[i][i];
err=fabs(x[i]-t);
if(err<maxerr)
maxerr=err;
x[i]=t;
}
printf("%5d",itr);
for(i=0;i<N;i++)
printf("%9.4f",x[i]);
printf("\n");
if(maxerr<aerr)
{
printf("Converges in %3d""iteration\n",itr);
for(i=0;i<N;i++)
printf("x[%3d]=%7.4f\n",i+1,x[i]);

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-425


Rev. No. : 00
Page No. 1 of 1

Aim of Experiment: - Numerical solution to an differential equation using Eulers method.


#include stdio.h>
float df(floatx,float y)
{
return x+y;
}
main()
{
float x0,y0,x,x1,y1,h;
printf("Enter the values of x0,y0,x,h");
scanf("%f%f%f%f",&x0,&y0,&h,&x);
x1=x0;
y1=y0;
while(1)
{
if (x1>x)
return;
y1+=h*df(x1,y1);
x1+=h;
printf("when x=%3.1f" "y=%4.2f\n",x1,y1);
}
}

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-426


Rev. No. : 00
Page No. 1 of 1

Aim of Experiment: - Solution to a non linear equation in single variable using the method of
successive Bisection.
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(x*x*x - (4*x)-9);
}
void bisect (float *x,float a, float b, int *itr)
{
*x = (a+b)/2;
++(*itr);
printf("\n iteration number = %3d, value of x = %7.5f",*itr,*x);
}
main()
{
int itr = 0,mitr;
float a,b,x,y,merr;
printf("enter the value of a,b""allowed error,maximum iterations \n");
scanf("%f%f%f%d",&a,&b,&merr,&mitr);
if (f(a)*f(b)>0)
{
printf("root doesnot lie in a and b");
return(0);
}
bisect (&x,a,b,&itr);
do
{
if(f(x)*f(a)<0)
b=x;
else
a=x;
bisect(&y,a,b,&itr);
if (fabs(y-x)<merr)
{
printf("\nafter %d iterations,root=%f \n",itr,y);
return(0);
}
x=y;
}while(itr<mitr);
printf("solution does not converge\n");
printf("iterations not sufficient");
return (1);

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-427


Rev. No. : 00
Page No. 1 of 1

Aim of Experiment: - Solution to a non linear equation in single variable using the method of
Newton raphons...
#include<stdio.h>
#include<math.h>
float f(float x)
{ return ((3*x)-cos(x)-1); }
float f1(float x)
{ return (3+sin(x));
}
main ()
{
float a,b,merr,h,x,y;
int itr,mitr;
clrscr();
printf("Enter the values of a,b,merr,x,mitr");
scanf("%f%f%f%f%d",&a,&b,&merr,&x,&mitr);
if(f(a)*f(b)>0)
{
printf("Root do not lie");
}
for(itr = 1;itr<=mitr;++itr)
{
h = f(x)/f1(x);
y=x-h;
printf("iteration = %3d,x= %7.5f",itr,x)l;
if(fabs (h) < merr)
{
printf("Root = %f",x); return(0);
}
x=y
}
printf("Root do not converge");
return(0);
}

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-428


Rev. No. : 00
Page No. 1 of 2

Aim of Experiment: - Numerical solution to an differential equation using Predictor Corrector


method.
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x,float y)
{
return(x-y*y);
}
float rk(float x0,float y0,float h)
{
float k1,k2,k3,k4,k;
k1=h*f(x0,y0);
k2=h*f(x0+h/2,y0+k1/2);
k3=h*f(x0+h/2,y0+k2/2);
k4=h*f(x0+h,y0+k3);
k=(k1+k2+2*(k2+k3)+k4)/6;
return(y0+k);
}
main()
{
clrscr();
float x[5],y[5],v[5],t,h,xt,merr,t0;
printf("enter the value of x[0],y[0],h,merr");
scanf("%f%f%f%f",&x[0],&y[0],&h,&merr);
v[0]=f(x[0],y[0]);
for(int i=1;i<=3;i++)
{
y[i]=rk(x[i-1],y[i-1],h);
x[i]=x[i-1]+h;
v[i]=f(x[i],y[i]);
}
y[4]=y[0]+4*h*(2*x[1]-v[2]+2*v[3])/3;
x[4]=x[3]+h;
v[4]=f(x[4],y[4]);
while(1)
{ t=y[2]+h
Y[4]=(v[2]+4*v[3]+v[4])/3;
Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-428


Rev. No. : 00
Page No. 2 of 2

t0=f(x[4],t);
if(fabs(t-y[4])<merr)
{
printf("value of y at%f,at x%f",t,x[4]);
break;
}
y[4]=t;
v[4]=t0;
}
}

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-429


Rev. No. : 00
Page No. 1 of 1

Aim of Experiment: - Solution to a non linear equation in single variable using the method of
Newton Raphons.
#include<stdio.h>
#include<math.h>
float f(float x)
{ return ((3*x)-cos(x)-1); }
float f1(float x)
{ return (3+sin(x));
}
main ()
{
float a,b,merr,h,x,y;
int itr,mitr;
clrscr();
printf("Enter the values of a,b,merr,x,mitr");
scanf("%f%f%f%f%d",&a,&b,&merr,&x,&mitr);
if(f(a)*f(b)>0)
{
printf("Root do not lie");
}
for(itr = 1;itr<=mitr;++itr)
{
h = f(x)/f1(x);
y=x-h;
printf("iteration = %3d,x= %7.5f",itr,x)l;
if(fabs (h) < merr)
{
printf("Root = %f",x); return(0);
}
x=y
}
printf("Root do not converge");
return(0);
}

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-430


Rev. No. : 00
Page No. 1 of 1

Aim of Experiment: - Solution to a system of simultaneous algebraic equations using the


Gaussian elimination procedure.
#include<stdio.h>
#define N 4
main()
{
float a[N] [N+1],x[N],t,s;
int i,j,k;
printf("Enter the elementsof the"
"augmented matrix rowwise\n");
for (i=0;i<N;i++)
for (j=0;j<N+1;j++)
scanf("%f",&a[i][j]);
for
(j-0;j<=N-1;j++)
for(i+1;i<N;i++)
{
t=a[i][j]/a[j][j];
for(k=0;k<N+1;k++)
a[i][k]=a[j][k]*t;
}
/*Now printing the upper triangular matrix*/
printf("The upper triangular matrix is\n",
for(i=0;i<N;i++)
for(j=0;j<N+1;j++)
printf("8.4f",a[i][j]);
printf("\n");
}
/*now performing back substitution*/
for(i=N;i>-0;i--)
{
s=0;
for(j=i+1;j<N;j++)
s+=a[i][j]*x[j];
x[i]=(a[i][N]-s)/a[i][j];
}
/*now printng the result*/
printf("The solution is\n");
for(i=0;i<N;i++)
printf("x[%3d]=%7.4f\n",i+1,x[i]);
getch();
}

Issued By:

Approved By:

Date of Issue:
02.02.09

QUALITY MANAGEMENT SYSTEM OF JMIT, RADAUR (HARYANA)


JMIT

Work Instructions

Doc. No: ECE/ MAT-206E /WI-431


Rev. No. : 00
Page No. 1 of 1

Aim of Experiment: - Solution to a non linear equation in single variable using the Secant .
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(3*x-cos(x)-1);
}
main()
{
int itr, mitr;
float x0,x1, merr, err, h, t;
printf("enter the values of x0, x1, merr, mitr");
scanf("%f%f%f%d", &x0, &x1, &merr, &mitr);
for(itr=1; itr<mitr; ++itr)
{
h=f(x0)*((x1-x0)/(f(x1)-f(x0)));
err=fabs(h);
t=x0-h;
printf("\n value of x is %7.5f in %d iterations", t,itr);
if(err<=merr)
{
printf("\n %f is the root ",t);
return(0);
}
x0=x1;
x1=t;
}
printf("the solution is not convergent in given iterations");
return(1);
}

Issued By:

Approved By:

Date of Issue:
02.02.09

You might also like