Flow Charts NM
Flow Charts NM
Start
Initialize itr
Is
Yes
(20 fabs (x1 -x)
< aerr?
No
(B
No Is Yes
itr < maxitr (10)x= (a +b)/2.0
Path of Success for Civil & Mechanical Engineering MPSC, GATE &IES
Numerical Method IITian's Academy,Pune Akash Nalwade Sir
X0 = x1;
printf (" Iterations not sufficient, "
"solution does notconverge/n");
return1:;
}
bodbsModgsnotvwsMS
Start
h=f(x0)/df(<0)
x1= x0 -h
Print itr, x1
Is
Yes
fabs (h) Print solution
<aerr ?
No
Stop
X0 = x1
Print 'Solution
does not converge.
Stop
Path of Success for Civil & Mechanical Engineering MPSC, GATE & IES
Numerical Method IITian'sAcademy, Pune Akash Nalwade Sir
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");
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
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
Akash Nalwade Sir
Numerical Method IITian's Acadeny, Pune
Start
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
Program :
|* Gauss Seidal method */
# include<math.h>
# defineN4
main ()
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
Gaus
Start
Initializex to 0
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
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) ;