# To evaluate ordinary differential equations by RK-4 (Classical) Method

Evaluating ordinary differential equations by RK-4 or classical method both order first and second

//To compute ordinary differential equations by RK-4 or classical method for order first

#include

#include

#include

void main()

{

cout<<“\t first order R-K 4th Classical Method\t”<

double h,n,m1,i,m2,m3,m4,x[100],y[100];

cout<<“Number of intervals “;

cin>>n;

cout<

cout<<“Enter the value of h”<<<“h = “;

cin>>h;

cout<<“Enter the value of x0″<<<“x0 = “;

cin>>x[0];

cout<<“Enter the value of y0″<<<“y0 = “;

cin>>y[0];

cout<

for(i=0;i<=n;i++)

{

x[i+1]=x[i]+h;

m1=h*.5*(1+x[i])*(y[i]*y[i]);

m2=h*.5*(1+(x[i]+.5*h))*(y[i]+m1*.5*h)*(y[i]+m1*.5*h);

m3=h*.5*(1+(x[i]+.5*h))*(y[i]+m2*.5*h)*(y[i]+m2*.5*h);

m4=h*.5*(1+(x[i]+h))*(y[i]+m3*h)*(y[i]+m3*h);

y[i+1]=y[i]+(m1+2.0*m2+2.0*m3+m4)/6;

cout<<“x”<<<“= “<<

cout<<“y”<<<“= “<<

cout<

}

getch();

}

// To compute ordinary differential equations by RK-4 or classical method for order second

#include

#include

#include

void main()

{

cout<<“\t 2nd order order R-K 4th Order Method\t”<

double h,n,m1,i,m2,m3,m4,p1,p2,p3,p4,x[100],y[100],z[100];

cout<<“Number of intervals “;

cin>>n;

cout<

cout<<“Enter the value of h”<<<“h = “;

cin>>h;

cout<<“Enter the value of x0″<<<“x0 = “;

cin>>x[0];

cout<<“Enter the value of y0″<<<“y0 = “;

cin>>y[0];

cout<<“Enter the value of z0″<<<“z0 = “;

cin>>z[0];

cout<

for(i=0;i<=n;i++)

{

x[i+1]=x[i]+h;

m1=h*z[i];

p1=h*(6*x[i]+3*y[i]-2*z[i]);

m2=h*(z[i]+.5*p1);

p2=h*(6*(x[i]+.5*h)+3*(y[i]+m1*.5)-2*(z[i]+.5*p1)) ;

m3=h*(z[i]+.5*p2);

p3=h*(6*(x[i]+.5*h)+3*(y[i]+m2*.5)-2*(z[i]+.5*p2)) ;

m4=h*(z[i]+.5*p3);

p4=h*(6*(x[i]+.5*h)+3*(y[i]+m3*.5)-2*(z[i]+.5*p3)) ;

y[i+1]=y[i]+(m1+2.0*m2+2.0*m3+m4)/6;

z[i+1]=z[i]+(p1+2.0*p2+2.0*p3+p4)/6;

cout<<“x”<<<“= “<<

cout<<“y”<<<“= “<<

cout<<“z”<<<“= “<<

cout<

}

getch();

}

To evaluate ordinary differential equations by RK-4 (Classical) Method in C++ Programming Language for Numerical Methods for Engineering Students

# To calculate the value of an integer using Trapezoidal rule both when functional values are both given and values NOT given independently

Trapezoidal rule can be applied to find the value of a limiting integer programmatically in both cases whether individual functional values are given or not. A complete algorithm follows the both process below.

/*********

Trapezoidal rule complete algorithm

1. start

2. read n= no of intervals

3. read initial and final values ie a,b

4. h=(b-a)/n;

5. set x[0]=a; x[n]=b;

6. next element

i= 1 to n-1

x[i]=x[i-1]+h

i=0 to n

f[i]=function or input functional values as cin<

8. 1st &last terms

sum=f[0]+f[n]

9. i= 1 to n-1

sum= sum + 2 * ( f[i] )

10. sum=h/2*sum

11. display sum

12. stop

***********/

//To calculate the value of an integer using Trapeziodal Rule (no corressponding functional values provided)

#include

#include

#include

#include

void main()

{

double n,i,a,b;

double x[20],f[20], sum;

float h;

clrscr();

cout<<<“Enter no of intervals: “;

cin>>n;

cout<<<“Enter limiting values:\t”;

cin>>a>>b;

h=(b-a)/n;

x[0]=a;

x[n]=b;

for(i=1;i<=n-1;i++)

{

x[i]=(x[i-1]+h);

}

for(i=0;i<=n;i++)

{

f[i]=exp(x[i]*tan(x[i]));

}

sum=f[0]+f[n];

for(i=1;i<=n-1;i++)

{

sum=sum+(2*f[i]);

}

sum=(h/2.0)*sum;

cout<<<“The required integral value = “<

getch();

}

/* To evaluate value of an integral using Trapezoidal Rule when the functional values are given */

#include

#include

#include

#include

void main()

{

double n,a,b,h,sum,x[20],i,f[20];

clrscr();

cout<<“To Calculate The Integral Value Using Trapezoidal Rule”<

cout<

cout<<“The given functional vaue is e^(x*tanx) \n”<

cout<<“Enter the Number of interval “;

cin>>n;

cout<<“There are “<<<” intervals\n”<

cout<<“Enter the initial point\t”<

cin>>a;

cout<<“Enter the final point\t”<

cin>>b;

cout<<“The limit of integration is from “<<<“to”<<<

h=(b-a)/n;

x[0]=a;

x[n]=b;

cout<

for(i=1;i<=n-1;i++)

{

x[i]=x[i-1]+h;

}

cout<<“Enter the functional value accordingly \n”;

for(i=0;i<=n;i++)

{

cout<<“f”<<<“= “;

// f[i]=exp(x[i]*tan(x[i])) ;

cin>>f[i];

}

sum=f[0]+f[n];

for(i=1;i<=n-1;i++)

{

sum=sum+2*f[i];

}

sum=(h/2)*sum;

cout<<“The required value of integration is”<

getch();

}

To calculate the value of an integer using Trapezoidal rule both when functional values are given and values NOT given in C++ Programming Language for Numerical Methods for Engineering Students

# To calculate the Inverse of a Matrix using Gauss Jordon Method

Program to calculate the Inverse of a Matrix using Gauss Jordon Method, a simple yet complete algorithm follows below.

Gauss Jordon Method can be employed to solve a system of linear equations having solutions. Unlink in Gauss Elimination method (in which triangular matrix is formed), in Gauss Jordon Method all off diagonal elements are eliminated producing a diagonal matrix. Finally, inverse of the matrix formed by system of equations is computed.

[A:I]?[I:A-1]

where

[A]= matrix to be solved for

[A-1]= required inverse matrix

# List of Program in Numerical Methods

Here are few programs written in C++ Programming Language for the Numerical Methods course for beginner Engineering Students. Sample codes, executing files and sometimes background theory can be found. Please, report back if you came across broken links or incorrect coding or anything you found to complain about. Queries will be replied.

1. To write a program to calculate the roots of a quadratic equation ie ax^2+bx+c=0
2. To calculate the real roots of an equation using Bisection Method
3. To calculte the real roots of an equation using Regula Falsi (Bracketing) Method
4. To calculate atleast one root of a cubical equation correct to 3 decimal place using Newton Raphson (NR) Method
5. To understand and use Lagrange’s Interpolation for a polynomial to determine functional value of data
6. To solve the linear equation using Gauss Elimination Method
7. To calculate the Inverse of a Matrix using Gauss Jordon Method
8. To calculate the value of an integer using Trapezoidal rule both when functional values are given and values NOT given
9. To evaluate ordinary differential equations by RK-4 (Classical) Method

.

# Numerical Methods EG601SH

Course Objectives
To present the theory of numerical computational procedures for solving engineering problems. Solution of ordinary and partial differential equations will be included.

1.0 Solution of Nonlinear Equations:(10 hours)
1.1 Review of calculus, continuity, differentiability, intermediate value theorem, Taylor’s theorem
1.2 Absolute, relative, and round off errors, error bounds for computational errors
1.3 Bisection method, its error bounds and convergence
1.4 Newton’s method, secant method and their convergence
1.5 Fixed point iteration, its convergence properties,
1.6 Zeros of polynomials by Horner’s method

2.0 Interpolation and Approximation:(10 hours)
2.1 Taylor’s polynomial approximation, Lagrange’s interpolation
2.2 Newton’s interpolation and divided differences
2.3 Iterative interpolation
2.4 Cubic spline interpolation
2.5 Least squares method of fitting continuous and discrete data or functions

3.0 Numerical Differentiation and Integration:(5 hours)
3.1 Numerical differentiation formulas
3.2 Newton-Cote’s numerical integration formulas, composite numerical integration
3.3 Romberg integration algorithm
3.4 Gaussian integration formulas

4.0 Linear Algebraic Equations:(10 hours)
4.1 Review of the properties of matrices
4.2 Matrix form of Gaussian elimination, pivoting strategies, ill-conditioning
4.3 Cholesky’s and related algorithms for matrix factorization
4.3 Eigen values and eigen vectors and the power method

5.0 Solution of ordinary Differential Equations:(7 hours)
5.1 Euler’s method for solving ordinary differential equations of 1st order and other related methods
5.2 Runge-Kutta methods
5.3 Extension to higher order equations
5.4 Initial value problems
5.5 Boundary value problems
6.0 Solution of partial Differential Equations: (3 hours)
6.1 Introduction to the solution of partial differential equations
6.2 Engineering examples

Reference Books:
1.0 W. Cheney and D. Kincaid, “Numerical Mathematics and computing”, Edition, Brooks/Cole publishing Co.,1985.
2.0 C.F. Gerald and P. O. Wheatley, “Applied Numerical Analysis”, 4th Edition, Addison-Wesley Publishing Company, New York.
3.0 S. Yakowitz and F. Szidarovszky, “An Introduction to Numerical Computations”, 2nd Edition, Macmillan publishing Co., New York.

Reference Book for Programs in C:
1.0 W.H. press, B. P. Flannery et. al., “Numerical Recipes in C”, 1st Edition, Cambridge Press,1988.

# To solve the linear equation using Gauss Elimination Method

Program to solve the linear equation using Gauss Elimination Method, the complete algorithm for Gauss Elimination Method is given below.

The Gauss Elimination process involves two techniques for solving linear equation. The first one is forming upper triangular matrix by forward elimination and the second is using backward substitution method to find the unknown values.

//lab 6 to solve the linear equation using Gauss Elimination method.

/*  complete algorithm for Gauss Elimination Method

1. read n number of equation

2. for i=1 to n

3. for j=1 to n+1

5. end for j

6. end for i.

7. for k=1 to n-1

for i=k+1 to n

9. pivot=aik/akk

10. for j=1 to n+1

11. aij=aij-(pivot*akj)

12. end for j

13. end for i

14. end for k

15. xn=a(n n+1)/a(n n)

16. for k=n-1 to 1

17. sum=0.0

18. for j=k+1 to n

19. sum =sum+(akj*xj)

20. end for j

21. xk=(a(k n+1) -sum)/akk

22. end for k

23. for i=1 to n

24. print xi

25. end for i

26. stop

*/

#include

#include

#include

#include

void main()

{

double n,i,j, k;

double sum, pivot, a[10][10], x[10];

clrscr();

cout<<“Enter No of equations, n :\t”;

cin>>n;

cout<<<“\tDONOT ENTER DIAGONAL ELEMENT ZERO\n”;

for(i=1;i<=n;i++)

{

cout<<<“Supply coefficients of “<<<” equation”<

for(j=1;j<=n+1;j++)

{

cout<<“a”<<<<“=\t”;

cin>>a[i][j];

}

}

/* Start of Elimination */

for(k=1;k<=n-1;k++)

{

for(i=k+1;i<=n;i++)

{

pivot=a[i][k]/a[k][k];

for(j=1;j<=n+1;j++)

a[i][j]=(a[i][j]-(pivot*a[k][j]));

}

}

/* Start Back Substitution */

x[n]=(a[n][n+1]/a[n][n]);

for(k=n-1;k>=1;k–)

{

sum=0.0;

for(j=k+1;j<=n;j++)

{

sum=sum+(a[k][j]*x[j]);

}

x[k]=(a[k][n+1]-sum)/a[k][k];

}

/* Displaying Result */

cout<<<“Required roots are:”<

for(i=1;i<=n;i++)

cout<<” x”<<<“= “<<

getch();

}

To solve the linear equation using Gauss Elimination Method in C++ Programming Language for Numerical Methods for Engineering Students

# To calculate the real roots of an equation using Bisection Method

Roots of a quadratic or polynomial can be computed using Bisection Method.

The only difference that lies between the bisection method and the regula falsi method is the way the next new point x0 is found.

The bisection method is linearly convergent as error decreases linearly with step each by a factor of 0.5. However, since the convergence is slow to achieve a higher degree of accuracy, a large number of iterations might be needed.

The false point is based on linear interpolation model in which during each iteration one of the starting points is fixed while the other tends to move toward the solution of the equation.

To calculate the real roots of an equation using Bisection Method in C++ Programming Language for Numerical Methods for Engineering Students

# To calculate the real roots of an equation using Regula Falsi (Bracketing) Method

Program to calculte the real roots of an equation using Regula Falsi (Bracketing) Method

The only difference that lies between the bisection method and the regula falsi method is the way the next new point x0 is found.

The bisection method is linearly convergent as error decreases linearly with step each by a factor of 0.5. However, since the convergence is slow to achieve a higher degree of accuracy, a large number of iterations might be needed.

The false point is based on linear interpolation model in which during each iteration one of the starting points is fixed while the other tends to move toward the solution of the equation.

To calculte the real roots of an equation using Regula Falsi (Bracketing) Method in C++ Programming Language for Numerical Methods for Engineering Students

# To calculate atleast one root of a cubical equation correct to 3 decimal place using Newton Raphson (NR) Method

Program to calculate atleast one root of a cubical equation correct to 3 decimal place using Newton Raphson (NR) Method

To calculate atleast one root of a cubical equation correct to 3 decimal place using Newton Raphson (NR) Method in C++ Programming Language for Numerical Methods for Engineering Students

# To understand and use Lagrange’s Interpolation for a polynomial to determine functional value of data

Program to understand and use Lagrange’s Interpolation for a polynomial to determine functional value of data

Lagrange’s Interpolation for a polynomial is used to determine nature of a polynomial with its degree based upon number of input values. As a polynomial is constructed, it is matched for the given data value to verify or to compute its functional value. This is all done by programming for Lagrange’s Polynomial.

/* To calculate the functional value using Lagrange’s Interpolation */

#include
#include
#include
#include

void main()
{
double n, a, k, value, x[10], f[10], p[10];
clrscr();
cout<<“Enter the no of data:\t”;
cin>>n;

cout<<<<“Enter the input values:\t”;
for(int i=1;i<=n;i++)
{
cin>>x[i];
cout<<<“\t”;
}

cout<<<<“Enter the respective functional values:\t”;
for(i=1;i<=n;i++)
{
cin>>f[i];
cout<<<“\t”;
}

cout<<<“Supply the data whose functional value is to be determined:\t”;
cin>>a;

for(k=1;k<=n;k++)
{
p[k]=1.0;
for(i=1;i<=n;i++)
{
if(i!=k)
p[k]=p[k]*(a-x[i])/(x[k]-x[i]);
}
}

value=0.0;
for(i=1;i<=n;i++)
{
value=value+(p[i]*f[i]);
}

cout<<<<“Required functional value for “<<<” is “<<<“.”;

getch();
}

To understand and use Lagrange’s Interpolation for a polynomial to determine functional value of data in C++ Programming Language for Numerical Methods for Engineering Students