0% found this document useful (0 votes)
9 views14 pages

Flow Charts NM

The document outlines various numerical methods including Bisection, Newton-Raphson, Gauss Elimination, Gauss Jordan, Gauss Seidal, Trapezoidal Rule, and Simpson's Rule, along with their respective algorithms and flowcharts. Each method is presented with a programmatic approach in C, detailing the necessary steps and calculations involved in finding roots and solving equations. The content is aimed at students in Civil and Mechanical Engineering, specifically for MPSC, GATE, and TES examinations.

Uploaded by

kartik vasave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views14 pages

Flow Charts NM

The document outlines various numerical methods including Bisection, Newton-Raphson, Gauss Elimination, Gauss Jordan, Gauss Seidal, Trapezoidal Rule, and Simpson's Rule, along with their respective algorithms and flowcharts. Each method is presented with a programmatic approach in C, detailing the necessary steps and calculations involved in finding roots and solving equations. The content is aimed at students in Civil and Mechanical Engineering, specifically for MPSC, GATE, and TES examinations.

Uploaded by

kartik vasave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Numerical Method IITian's Academy, Pune Akash Nalwade Sir

Algorithms and Flow Chart


1. By Section Method
Program :
|* Bisection method*/
#incude<stdio.h>
#incude <math.h>
float f (float x)
return (**x*x-4*x-9);
void bisect (float*x, float a,float b,int itr)
*x= (a +b) /2;
++ (* itr);
printf ("Iteration no. %3d X=%7 .5/n", *itr, x);
main ()
int itr = 0, maxitr ;
float x, a, b, aerI, X1;
printf ("Enter the values of a, b, "
"allowed error, maximum iterations/n")
;iir
scanf ("%f %f %f %d", &&a, &b, &aerr, &maxitr);
bisect (&x, a, b&itr);
do
{
if ({ (a)*f (x) <0)
b=x;
lese
a=x;
bisect (&&x1, a, b, &itr);
if (fabs (x1-x)<aerr)
print f ("After %d iterations, root< 169>
W=%6.4 f/n", itr, x1);
return 0;
x=X1;
}while(itr<mxitr);
print ("Soltion does not converge,"
" iterations not sufficient );
return 1;

Path of Success for Civil &Mechanical Engineering MPSC, GATE &TES


Numerical Method IITian'sAcademy, Pune Akash Nalwade Sir

Start

| Define function f(x)

Define function bisect

Get the values of


a, b, aerr, maxitr

Initialize itr

Call function bisect


with x, a, b, itr (B)
(10)
Yes Is No
b=x f(a)*{(x) a =x
<0?

Call function Bisect


with x1, a, b, itr

Is
Yes
(20 fabs (x1 -x)
< aerr?
No

(B

No Is Yes
itr < maxitr (10)x= (a +b)/2.0

Print 'solution itr =itr+1


does not converge
(20) Print itr, x1
Stop
Print itr, x1 Return

Path of Success for Civil & Mechanical Engineering MPSC, GATE &IES
Numerical Method IITian's Academy,Pune Akash Nalwade Sir

2. Newton Raphson Method


Program:
\*Newton Raphson Method*/
#include<stdio.h>
# include <math.h>
Aloat f (float x)

return x*1og10 ()-1.2;


float df (float x)
{
return log10(%) +0.43429;
main ()

int itr, maxitr;


float h, x, x1, aerr ;
printf ("Enter x0, allowed error,"
"maximum iterations \n");
scanf (" %f% f %
d", &x0, &raerr, &emaxitr);
for (itr =1, itr <= maxitr; itr + ++
{
h=f(«0)/ df(x0);
x1=x0-h;
printf ("teration no. %3d,"
"x=%9.6f/n", itr, x1);
if (fabs (h)<aerr)

print f ("After %3d iterations, "


"root=%8.6f/n", itr, x1);
return 0;

X0 = x1;
printf (" Iterations not sufficient, "
"solution does notconverge/n");
return1:;
}

Path of Success for Civil &Mechanical Engineering MPSC, GATE &IES 3


Numerical Method IITian'sAcademy, Pune Akash Nalwade Sir

bodbsModgsnotvwsMS
Start

| | Define function f(x)

Define function df(x)

Get the values of


X0, aerr, maxitr

Loop for itr = 1 to matrix

h=f(x0)/df(<0)
x1= x0 -h

Print itr, x1

Is
Yes
fabs (h) Print solution
<aerr ?

No
Stop
X0 = x1

End Loop itr

Print 'Solution
does not converge.

Stop

Path of Success for Civil & Mechanical Engineering MPSC, GATE & IES
Numerical Method IITian'sAcademy, Pune Akash Nalwade Sir

3.Gauss Elimination Method


Program :
1*Gauss elimination method*/
#include<stdio.h>
#define N4
main()

float a [NI[N+1], x [N; t, s;


int i, j, k;
print f ("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;1++)

t=a[i][j]/a [jJLj1;
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++)
print f("%8.4f", a[i] [i]);
print f(" /n");

/*now performing back substitution*/


for (i=N-1;i>=0;i--)
s=0;
for (j=i+1;j <N;j++)

Path of Successfor Civil &MechanicalEngineering MPSC, GATE &IES 5


Numerical Method IITian's Academy, Pune Akash Nalwade Sir

s+=a[iJj]*x[jl
x[i]=(a[i][N]-s)/a [i][i];
/*now printing the results */
print f(" The solution is: -\ n");
for (i=0;i<N;i++)
print f ("x [%3d] =%7.4f\n", i+1, x[i]):

Path of Success for Civil & Mechanical Engineering MPSC, GATE & IES
Numerical Method IITian'sAcadeny, Pune Akash Nalwade Sir

borisMleasD4
Start

Get the Augmented 1hodksabotsens


Matrix in Array a
6Mentsbt
Loop for j= 0 to N-2

Loop for i=j+1 to N -1

t=a [i] [jV a[j][j]


Loop for k=0to N

a[i] [k]=alj] [k<*t


End Loop (k)
End Loop (i)
End Loop ()
Print upper
triangular matrix
Loop for i =N-1to 0step-1|[jiila
s=0

Loop forj=i+1 to N
st=a[i] i) *xi]
End Loop ()
x[i] = (a[i]N] - s)/a[iI [Ü
End Loop[i]
Print Solution

Stop

Path of Success for Civil &Mechanical Engineering MPSC, GATE &IES


Numerical Method IITian's Academy, Pune Akash Nalwade Sir

4.Gauss Jordan Method


Program :
\* Gaussjordan method*/
#incude <stdio.h>
# defineN3
main ()

float a [N] [N+1], t;


int i, j, k;
printf ("nter the elements of the"
"augmented matrix rowwise/n");oco
for (i =0;i<N;i+ +)
for (j=0;j<N+1;j++)e-je
scanf ("%f", &a [i]lj]) ;
/*now calculating the values
of x1,x2, ... xN*/
for (j =0;j<Nij++)
for (i=0;i<N;it+)
if (i!=j)
t=a[i][j]/a [j][jl:
for (k =0;k<N+1;k++)
a[i][k]-=a[j][k]*t;
/*now printing the diagonal matrix*/
print f("The diagonal matrix is :-\n");
for (i=0;i<N;i++)
{
for (j=0;j<N+1 ;j++)
print f ("%9.4 f",a[i][j]):
print f(" \n");
J*now printing the results */
print f("The solution is :-\n");
for (i=0;i<N;i++)
print f("x [%3d]= %7.4f\n",
i+1,a[i][N]/a[iJ[iD;

Path of Success for Civil & Mechanical Engineering MPSC, GATE & IES
Akash Nalwade Sir
Numerical Method IITian's Acadeny, Pune

Start

Get the Augmented


Matrix in Array a

Loop forj=0 to N -1 |
Loop for i=0toN-1

No
KIs i!=j?
Yes
t=a[i] ij]la[j] ij]
Loop fork= 0 to N
(
a[i] [k] -= a[jl [k] "t|
End Loop (k)

End Loop()
End Loop )
/Print diagonal matriX
Stop

Path of Success for Civil & Mechanical Engineering MPSC, GATE & IES
Numerical Method IITian's Academy, Pune Akash Nalwade Sir

5. Gauss Seidal Method

Program :
|* Gauss Seidal method */
# include<math.h>
# defineN4
main ()

float a[N] [N+1], x [N], aerr, maxerr,


t,s, err;
int i, j, itr,maxitr ;
*firstinitializing the array x*/
for(i=0;i<N;i++) x [i]=0;
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]);
print f("Enter the allowed error, "
"maximum iterations\n");
scanf ("%f %d",&aerr, &maxitr);
print f("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<Nj++)
if (J!=i)st=a[i][j]*x[j1:
t= (a[i] [N] -s)/a[i][i]:
err =fabs (x [i]-t);
if (err>maxerr) maxerr =err;
x[i]=t;

print f("%5d",itr);
for (i=0;i<N;i++)

10 Path of Success for Civil & Mechanical Engineering MPSC, GATE & IES
Numerical Method IITian's Academy, Pune Akash Nalwade Sir

print f ("% 9.4 f",x [i]);


print f("\n");
if (maxerr<aerr)

print f("Converges in %3d"


"iterations \ n",itr);
for (i=0;i<N;i++)
print f("x [%3d]=%7.4f \n",
i+1,x[i]);
return 0;

} print f("solution does not converge,


"iteratiorns not sufficient \n");
return 1;

Path of Success for Civil&Mechanical Engineering MPSC, GATE & TES 11


Numerical Method Akash Walwade Sir
IITian'sAcademy, Pune

Gaus
Start

Initializex to 0

Get the element of


Augmented Matrix
in Array a
Get the values of
aerr, mnatrix

Print Heading
|Loop for itr = 1 tomaxitr End Loop (1)
Maxerr=0 Print Results
of Iteration
|Loop for i=0toN-1|
s=0
Is Yes
maxerr < aerr Print solutiony
Loop for j=0to N-1|
No Stop
End Loop (itr)
<Ís j!=i? s+=a LJ] *x| Print Solution
does not converg
End Loop ) Stop
t= (a[i] [N]- s)/a[i] [I|
err =fabs (x[i] - t)
Is Yes
err > maxerr maxerr =ert

INo
x[i] =t

12 Path of Success for Civil &Mechanical Engineering MPSC, GATE &IES


Numerical Method IITian'sAcademy, Pune Akash Nalwade Sir

5.Trapezoidal Rule
Program :
|* Trapezoidal rule*/
#include<stdio.h>
float y (float x)
{
return 1/(1+x*x);

main ()
float x0, xn, h,s;
int i, n ;
puts ("Enter x0, Xn, no. of subintervals" );
scant ("%f %f %d", &x0,&xn, &n);
h=(n-x0) /n;
S=y (x0) ty (n);
for (i =1;i<n=n-1;i++)
st=2*y (x0 +i*h) ;
print f (" Value of integral is %6.4f\n",
(h/2) *s) :

Path of Success for Civil & Mechanical Engineering MPSC, GATE & IES 13
Numerical Method Akash Nalwade Sir
IITian'sAcademy, Pune

6. Simpson's Rule
Program:
|* Simpson's rule*/
#include<stdio.h>
float y (float x)
return 1/ (1 +x*x);
main ()
float x0, xn,h,s;
int i, n;
puts("Enter x0, Xn, no. of subintervals" ):
scant ("%f %f %d",&x0, &Xn, &n);
h=(n-x0)/n;
S=y (x0) +y (xn) +4 *y (x0 +h);
for (i=3;i<=n-1;i+=2)
st=4*y (x0 +i*h) +2*y (x0 +(i-1) *h);
print f (" value of integral is %6.4f\n",
(h/3) *s) ;

- Flao chat way Ss slab


prograrm kor destgotg
lous chart or dddDHOn nulthpliraton o 2 (3x g) matrices A 2&
Algoithm rools by Neuston aphsoo mettod
Algort hr 2fiow chart a fin d1ng rosts by BisocHon method.

14 Path of Success for Civil & Mechanical


Engineering MPSC, GATE & IES

You might also like