ME 5th Sem Lab Manual_new
-
Upload
nikhil-batra -
Category
Documents
-
view
113 -
download
3
Transcript of ME 5th Sem Lab Manual_new
![Page 1: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/1.jpg)
GS MVN INSTITUTE OF ENGINEERING & TECHNOLOGY
PALWAL (HARYANA)
LAB MANUAL
APPLIED NUMERICAL TECHNIQUES
AND COMPUTING LAB ( ME-319 E )
Department-CSE
H.O.D (CSE/IT) Faculty
(Mr. P.C.VASHIST) (MAHENDRA PAL SINGH)
1
![Page 2: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/2.jpg)
GS MVN INSTITUTE OF ENGINEERING & TECHNOLOGY
INDEX
S.No Document Description Document ID Page No
1 Time Table GS/ME/ANTC/TT
2 Syllabus GS/ME/ANTC/SB
3 Lab Plan GS/ME/ANTC/CP
4 Attendance Register GS/ME/ANTC/AR
Branch: - ME
Subject Name:- APPLIED NUMERICAL TECHNIQUES AND COMPUTING LAB.
Subject Code:- ME-319 E
H.O.D FACULTY
(Mr. P.C.VASHIST) (Mahendra Pal Singh)
2
![Page 3: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/3.jpg)
ME- 319 E APPLIED NUMERICAL TECHNIQUES AND COMPUTING LAB.
Sessional marks : 25 Practical marks : 25
1. Solution of Non-linear equation in single variable using the method of successive bisection.
2. Solution of Non-linear equation in single variable using the Newton Raphson, Secant, Bi_ Section and Modified Euler’s method.
3. Solution of a system of simultaneous algebraic equations using the Gaussian elimination procedure.
4. Solution of a system of simultaneous algebraic equations using the Gauss-Seidel iterative method.
5. Solution of a system of simultaneous algebraic equations using the Gauss-Seidel iterative method employing the technique of successive relaxation.
6. Numerical solution of an ordinary differential equation using the Euler’s method.
7. Numerical solution of an ordinary differential equation using the Runge-Kutta 4th order method.
8. Numerical solution of an ordinary differential equation using the Predictor-corrector method.
9. Numerical solution of a system of two ordinary differential equation using Numerical integration.
10. . Numerical solution of an elliptic boundary value problem using the method of Finite Differences.
The students will be required to carry out the following exercises, that are based on the theory course ME-311 Numerical Methods and Computing, with the help of MATLAB software / Pascal / C / C++ on personal computer.
3
![Page 4: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/4.jpg)
GS MVN INSTITUTE OF ENGINEERING & TECHNOLOGY HARYANA
Course Description
Faculty : MAHENDRA PAL SINGH
Subject Title: APPLIED NUMERICAL TECHNIQUES AND COMPUTING LAB.
Subject Code: ME-319 E
Course Objective:
Applied Numerical Techniques and Computing lab are essential part to solution of any Numerical like linear, non-linear equation. Similarly, a course in Applied Numerical Techniques and Computing is also an essential part of any numerical method. This course is intended to serve as a guideline for student to learn the basic concepts of engineering mathematics . We will be discussing how to solve numerical equations with the help of computer in C/C++ language.
Learning Outcomes:
Introduced to the fundamental concepts numerical method. Able to solve the differential equation with the help of computer .
Able to answer the problems related to the concepts and functions of the following components:
Gauss-Seidel iterative method.
Euler’s method
Runge-Kutta 4th order method.
4
![Page 5: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/5.jpg)
GS MVN INSTITUTE OF ENGINEERING & TECHNOLOGY
HARYANA
Evaluation scheme:
Internal lab = 15 marks
Lab File = 5 marks
Attendance = 5 marks
Total internal marks = 25 marks.
M.D.U.Exam. marks = 25 marks
Total = 50 marks
5
![Page 6: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/6.jpg)
GS MVN INSTITUTE OF ENGINEERING & TECHNOLOGY
HARYANA
Weekly Lab Plan
SR. No
week Lab Lab topic Date Sign
1 1 Lab-1
1. Solution of Non-linear equation in single variable using the method of successive bisection.
22
Lab-2
2. Solution of Non-linear equation in single variable using the Newton Raphson, Secant, Bi_ Section and Modified Euler’s method.
3 3 Lab-3
3. Solution of a system of simultaneous algebraic equations using the Gaussian elimination procedure.
44
Lab-4
4. Solution of a system of simultaneous algebraic equations using the Gauss-Seidel iterative method.
55
Lab-5
5. Solution of a system of simultaneous algebraic equations using the Gauss-Seidel iterative method employing the technique of successive relaxation.
6 6 Lab-66. Numerical solution of an ordinary differential equation using the Euler’s method.
7 7 Lab-7 7. Numerical solution of an ordinary differential equation using the Runge-Kutta 4th order method.
8 8 Lab-88. Numerical solution of an ordinary differential equation using the Predictor-corrector method.
9 9 Lab-99. Numerical solution of a system of two ordinary differential equation using Numerical integration.
6
![Page 7: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/7.jpg)
10 10 Lab-1010. Numerical solution of an elliptic boundary value problem using the method of Finite Differences.
/*PROGRAM 1 BISECTION METHOD*/
#include<stdio.h>
#include<conio.h
#include<math.h>
float f(float x){return (x*x*x+x*x-3*x-3);}void bisect(float *x,float a,float b,int *itr){*x=(a+b)/2;++(*itr);printf("Iteration no %3d x=%7.5f\n",*itr,*x);getch ();}main(){int itr=0,maxitr;float x,a,b,aerr,x1;clrscr();printf("enter the value of a,b\nallowed error\nmax iteration\n");scanf("%f%f%f%d",&a,&b,&aerr,&maxitr);bisect(&x,a,b,&itr);do{if(f(a)*f(x)<0)b=x;elsea=x;bisect(&x1,a,b,&itr);if(fabs(x1-x)<aerr){
7
![Page 8: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/8.jpg)
printf("after %d iteration, root<169>=%6.4f\n",itr,x1);return 0;}x=x1;}while(itr<maxitr);printf("solution does not converger iteration not sufficient");getch ();return 1;}
8
![Page 9: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/9.jpg)
OUTPUT -1 BISECTION METHOD
Enter the value of a,b,allowed error, maximum iteration.
1
2
.00000000005
18
Iteration no 1*=1.50000
Iteration no 2*=1.75000
Iteration no 3*=1.62500
Iteration no 4*=1.68750
Iteration no 5*=1.71875
Iteration no 6*=1.73438
Iteration no 7*=1.72656
Iteration no 8*=1.73047
Iteration no 9*=1.73242
Iteration no 10*=1.73145
Iteration no 11*=1.73193
Iteration no 12*=1.73218
Iteration no 13*=1.73206
Iteration no 14*=1.73199
Iteration no 15*=1.73203
Iteration no 16*=1.73204
9
![Page 10: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/10.jpg)
Iteration no 17*=1.73205
Iteration no 18*=1.73205
/*PROGRAM 2 SECANT METHOD*/
#include<stdio.h>#include<conio.h>#include<math.h>float f(float x){return (cos(x)-x*exp(x));}void main(){float x1,x2,x3,y1,y2,y3,acc;clrscr();printf("enter the value of initial auess x1=");scanf("%f",&x1);printf("\n enter the value of another guess x2=");scanf("%f",&x2);printf("enter the calue of accuracy=");scanf("%f",&acc);y1=f(x1);y2=f(x2);while(fabs(x2-x1)>acc){x3=(((x2*y1)-(x1*y2))/(y1-y2));y3=f(x3);x1=x2;y1=y2;x2=x3;y2=y3;}printf("\n the root x3=%f",x3);getch ();}
10
![Page 11: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/11.jpg)
OUTPUT-2 SECANT METHOD
Enter the value of x1
And x2
X1=0
X2=1
Accuracy =0.001
The root x3=0.517757
11
![Page 12: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/12.jpg)
/*PROGRAM 3 GAUSSIAN ELIMINATION PROCEDURE*/#include<stdio.h>#include<conio.h>#include<math.h>#define n 3void main(){float a[n][n+1],x[n],t,s;int i,j,k;clrscr();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]);for(j=0;j<n-1;j++)for(i=j+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;}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");}for(i=n-1;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][i];}printf("the solution is:-\n");
12
![Page 13: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/13.jpg)
for(i=0;i<n;i++)printf("x[%3d]=%7.4f\n",i+1,x[i]);getch();}
OUTPUT- 3 GAUSSIAN ELIMINATION PROCEDURE
Enter the elements of the augmented matrix rowwise
2 1 1 10
3 2 3 18
1 4 9 16
The upper tringular matrix is
2.0000 1.0000 1.0000 10.0000
0.0000 0.5000 1.5000 3.0000
0.0000 0.0000 2.0000 10.0000
The solution is
X[1]=7.0000
X[2]=9.0000
X[3]=5.0000
13
![Page 14: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/14.jpg)
/*PROGRAM 4 REGULA FALSI METHOD*/#include<stdio.h>#include<conio.h>#include<math.h>float f(float x){return (x*x*x+x*x-3*x-3);}void regula(float *x,float x0,float x1,float fx0,float fx1,int *itr){*x=x0-((x1-x0)/(fx1-fx0))*fx0;++(*itr);printf("Iteration no %3d x=%7.5f\n",*itr,*x);getch ();}main(){int itr=0,maxitr;float x0,x1,x2,x3,aerr;printf("enter the value of x0,x1\nallowed error\nmax iteration\n");scanf("%f%f%f%d",&x0,&x1,&aerr,&maxitr);regula(&x2,x0,x1,f(x0),f(x1),&itr);do{if(f(x0)*f(x2)<0)x1=x2;elsex0=x2;regula(&x3,x0,x1,f(x0),f(x1),&itr);if(fabs(x3-x2)<aerr){printf("after %d iteration, root=6.5f\n",itr,x3);getch ();return 0;}x2=x3;}
14
![Page 15: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/15.jpg)
while(itr<maxitr);printf("solution does not converges iteration not sufficient");return 1;}
OUTPUT- 4 REGULA FALSI METHOD
Enter the value of x0,y0,x1,allowed error, maximum iteration.
1
2
.00000000006
10
Iteration no 1*=1.57143
Iteration no 2*=1.70541
Iteration no 3*=1.72788
Iteration no 4*=1.73140
Iteration no 5*=1.73195
Iteration no 6*=1.73204
Iteration no 7*=1.73205
Iteration no 8*=1.73205
Iteration no 9*=1.73205
Iteration no 10*=1.73205
After 10 iteration, root =1.73205
15
![Page 16: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/16.jpg)
/*PROGRAM 5 RUNGE KUTTA 4TH ORDER METHOD*/
#include<stdio.h>#include<conio.h>#include<math.h>float f(float x,float y){return (x+y*y);}int main(){float x0,y0,h,xn,x,y,k1,k2,k3,k4,k;clrscr();printf("enter the value of x0,y0,h,xn");scanf("%f%f%f",&x0,&y0,&h,&x);x=x0;y=y0;printf("\n\n the execution of the program to the given problem\n");while(1) break;{if(x==xn)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,then y=%8.4f\n\n",x,y);}getch ();return 0;}
16
![Page 17: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/17.jpg)
OUTPUT- 5 RUNGE KUTTA 4TH ORDER METHOD
Enter the vallue of x0, yo, h, xn 0.0 1.0 0.2 0.2
When x=0.2000 y=1.2736
17
![Page 18: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/18.jpg)
/*PROGRAM -6 NEWTON RAPSHON METHOD*/#include<stdio.h>#include<conio.h>#include<math.h>float f(float x){return (x*log10(x)-1.2);}float df(float x){return (log10(x)+0.43429);}main(){int itr=0,maxitr;float x0,x1,h,aerr;clrscr();printf("enter the value of x0\nallowed error\nmax iteration\n");scanf("%f%f%d",&x0,&aerr,&maxitr);for(itr=1;itr<=maxitr;++itr){h=f(x0)/df(x0);x1=x0-h;printf("\nafter %d iteration x=%9.6f" ,itr,x1);getch ();if(fabs(h)<aerr){printf("\n\n\nafter %d iteration, root=%6.5f\n",itr,x1);getch ();return 0;}x0=x1;}printf("solution does not converger iteration not sufficient");getch ();return 1;}
18
![Page 19: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/19.jpg)
OUTPUT- 6 NEWTON RAPSHON METHODEnter the value of x0,allowed error, maximum iteration.
2
.000000005
10
Iteration no 1*=2.813170
Iteration no 2*=2.741109
Iteration no 3*=2.740646
Iteration no 4*=2.740646
Iteration no 5*=2.740646
Iteration no 6*=2.740646
Iteration no 7*=2.740646
Iteration no 8*=2.740646
Iteration no 9*=2.740646
Iteration no 10*=2.740646
Iterations not sufficient , solution does not converge.
19
![Page 20: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/20.jpg)
/*PROGRAM-7 GAUSS JORDAN MEHTOD*/
#include<stdio.h>#include<conio.h>#include<math.h>#define N 3 main(){float a[N][N+1],t;int i,j,k,n;clrscr();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]);for(j=0;j<N;j++)for(i=0;i<N;i++)if(i!=j){t=a[i][j]/a[j][j];for(k=0;k<N+1;k++)a[i][k]-=a[j][k]*t;}printf("the diagonal matrix is\n");for(i=0;i<N;i++){for(j=0;j<N+1;j++)printf("%9.4f",a[i][j]);printf("\n");}printf("the solution is:\n");for(i=0;i<N;i++)printf("x[%3d]=%7.4f\n",i+1,a[i][N]/a[i][i]);getch ();return 0;}
20
![Page 21: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/21.jpg)
OUTPUT-7 GAUSS JORDAN METHODenter the elements of the augmented matrix rowwise
2 1 1 10
3 2 3 18
1 4 9 16
the diagonal matrix is
2.0000 0.0000 0.0000 14.0000
0.0000 0.5000 0.0000 -4.5000
0.0000 0.0000 -2.0000 -10.0000
the solution is:
x[ 1]= 7.0000
x[ 2]=-9.0000
x[ 3]= 5.0000
21
![Page 22: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/22.jpg)
/*PROGRAM-8 SIMPSON 1/3 MEHTOD*/ #include<stdio.h>#include<conio.h>#include<math.h>float f(float x){return (1+x*x);}int main(){int i,n;float x0,xn,h,s;clrscr();printf("enter the value of x0,xn,n\n");scanf("%f%f%d",&x0,&xn,&n);h=(xn-x0)/n;s=f(x0)+f(xn)+4*f(x0+h);for(i=3;i<=n-1;i+=2)s+=4*f(x0+i*h)+2*f(x0+(i-h)*h);printf("the value of integral is %f",(h*s)/3);getch();return 0;}
22
![Page 23: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/23.jpg)
OUTPUT-8 SIMPSON 1/3 MEHTOD enter the value of x0,xn,n066the value of integral is 78.000000
23
![Page 24: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/24.jpg)
/*PROGRAM-9 TRAPEZOIDAL MEHTOD*/
#include<stdio.h>#include<conio.h>#include<math.h>
float f(float x){return(1+x*x);}int main(int argc,char*argv[]){int i,n;float x0,xn,h,s;clrscr();printf("enter the value of x0,xn,n\n");scanf("%f%f%d",&x0,&xn,&n);h=(xn-x0)/n;s=f(x0)+f(xn);for(i=1;i<=n-1;++i)s+=2*f(x0+i*h);printf("the value of integral is %f\n",(h/2)*s);getch();return 0;}
24
![Page 25: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/25.jpg)
OUTPUT-9 TRAPEZOIDAL MEHTOD
enter the value of x0,xn,n
0
6
6
the value of integral is 79.000000
25
![Page 26: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/26.jpg)
/*PROGRAM-10 MATRIX MULTIPLICATION */
#include<stdio.h>#include<conio.h>void main(){int a[4][4],b[4][4],p[4][4],i,j,k,m,n;clrscr();printf("enter the elements of first matrix\n");for(i=1;i<=2;i++)for(j=1;j<=2;j++)scanf("%d",&a[i][j]);printf("enter the elements of second matrix\n");for(i=1;i<=2;i++)for(j=1;j<=2;j++)scanf("%d",&b[i][j]);for(i=1;i<=2;i++){for(j=1;j<=2;j++){p[i][j]=0;for(k=1;k<=2;k++)p[i][j]+=a[i][k]*b[k][j];}}printf("resultant matrix is\n");for(i=1;i<=2;i++){for(j=1;j<=2;j++)printf("%4d",p[i][j]);printf("\n");}getch();}
26
![Page 27: ME 5th Sem Lab Manual_new](https://reader030.fdocuments.us/reader030/viewer/2022020110/553d14614a795980388b4b94/html5/thumbnails/27.jpg)
OUTPUT-10 MATRIX MULTIPLICATION enter the elements of first matrix
10
20
30
40
enter the elements of second matrix
10
20
30
40
resultant matrix is
700 1000
1500 2200
27