You are on page 1of 11

Numerical methods Flow Charts

1. Trapezoidal rule

Start

Define: f(x)

Input: a,b and n

Set: h=(b-a)/n
i=1
Sum=0

Calculate:
Sum=Sum+f(a+i*h)

No

Is i>=n

Yes

Calculate:
Sum=h/2*{(f(a)+f(b)+2*Sum}

Output: Sum

Stop
2. Simpsons 1/3rd rule

Start

Define: f(x)

Input: a,b and n

Set: h=(b-a)/n
i=1
Sum=0

Calculate:
Sum=Sum+f(a+i*h)

No

Is i>=n

Yes

Calculate:
Sum=h/2*{(f(a)+f(b)+2*Sum}

Output: Sum

Stop
3. Simpsons 3/8th rule
Start

Define: f(x)

Input: a and b

Set: h=(b-a)/3
Sum=0

Calculate:
Sum=Sum+3h/8*[f(a)+f(b)+3{f(a+h)+f(a+2h)}]

Output: Sum

Stop
4. Eulers Method
Start

Define: f(x,y)

Input x0,y0, n and


b

Set h=(b-a)/n
i=0

Calculate:
yi+1=yi+hf(xi,yi)
xi+1=xi+h No
i=i+1

Is i>n

Yes

Output xi,yi

Stop
5. Runge Kurtta 4th order Method

Start

Define: f(x,y)

Input x0,y0, n and


b

Set h=(b-a)/n
i=0

Calculate:
k1=hf(xi,yi)
k2=hf(xi+h/2,yi+k1/2)
k3=hf(xi+h/2,yi+k2/2) No
k4=hf(xi+h,yi+k3)
yi+1=yi+(k1+2(k2+k3)+k4)/6
xi+1=xi+h
i=i+1

Is i>n

Yes

Output xi,yi

Stop
6. Gauss Elimination Method

Start

Input no. of variables n and matrix A


rowwise a[1] [1] to a[n+1][n+1]

for k=1 to n-1


for i=k+1 to n
aa=a[j][k]
b=a[k][k]
for j=1 to n+1
a[i][j]=b*a[i][j]-aa*a[k][j]
end loop j
end loop i
end loop k

calculate
x[n]=a[n][n+1]/a[n][n];
for i=n-1 to 1
x[k]=a[k][n+1]
for j=k+1 to n
x[k]=x[k]-a[k][j]*x[j]
x[k]=x[k]/a[k][k]
end loop j
end loop k

for i=1 to n
output x[i]

Stop

7. Legrange Interpolation
Start

Input the no of data n,x and data


(x0,y0) to (xn-1,yn-1)

for i=1 to n-1


l[i]=1
for j=1 to n-1
l[i]=l[i]*(xx-x[j])/(x[i]-x[j]
end loop j
end loop i

Output xi,yi

Stop
8. Least square Method for y=a+bx

Start

Input the no of data n,x and data


(x0,y0) to (xn-1,yn-1)

Calculate
b= (nXY-XY)/( nx2-(X)2)
a= (Y-bX)/n

Output Equation y=a+bx


and y at x

Stop
9. Gauss Seidal Iteration Method

Start

Input no. of variables n and matrix A


rowwise a[1] [1] to a[n+1][n+1]

Continue while(fabs(x1[i+1]-x1[i]))>=0.0001 and fabs(x2[i+1]-x2[i]))>=0.0001


fabs(x3[i+1]-x3[i]))>=0.0001)

for(j=1 to n
if(i!=j)
sum=sum+a[i][j]*x[j]
end loop for j
temp=(a[i][n+1]-sum)/a[i][i]
x[i]=temp;
end loop for i

for i=1 to n
output x[i]

Start Stop
10. Newton forward Formula

Input the no of data n,xx and data


(x0,y0) to (xn-1,yn-1)

Calculate h=x[2]-x[1] and s=(xx-x[0])/h;


p=1
d=y[1]
for i=1 to n-1
for j=1 to n-i
y[j]=y[j+1]-y[j]
end loop for j
p=p*(s-i+1)/i
d=d+p*y[1]
end loop i

Output y at x=xx

Stop
11. Newton backward Formula

Start

Input the no of data n,xx and data


(x0,y0) to (xn-1,yn-1)

Calculate h=x[2]-x[1] and s=(xx-x[n])/h;


d=y[n];
p=1;
for i=n to 1 and k=1 to n-1
for(j=n;j>=1;j--)
y[j]=y[j]-y[j-1];
end loop for j
p=p*(s+k-1)/k;
d=d+p*y[n];
end loop for i and k

Output y at x=xx

Stop
Start
12. Horners Rule

Input the order of polynomial


equation n,x,coefficients a0 to an

Calculate pn=an
for i =n-1 to 0
pn-1 = pn*x+an-1
end loop for i

Output f0=p0

Stop
13. Bisecton Method

Start

Define: f(x)

Input initial initial x0,x1 such that f(x1) and


f(x2) are of opposite sign

Continue while fabs(f(x3))>=0.0001


x3=(x1+x2)/2
if f(x1) and f(x3) are of same sign
x1=x3
if f(x2) and f(x3) are of same sign
x2=x3
else
x1=x3
x2=x3
Output root x3

Stop Start

14. Newton Raphson Method


Define: f(x)

Input initial initial x0,x1 such that f1(x1) is


not equal to 0

Continue while fabs(f(x2))>=0.0001


x2=x1- f(x1)/f1(x1)
x1=x2

Output root x2

Stop
15. Secant Method
Start

Define: f(x)

Input initial initial x1,x2

Continue while fabs(f(x3))>=0.0001


x3=x2-f(x2)(x2-x1)/(f(x2)-f(x1))

Output root x3

Stop
16. Fixed Point Iteration Method

Start

Define: f(x) and xi+1=g(xi)

Input initial initial x0

i=0
Continue while fabs(f(xi))>=0.0001
xi+1=g(xi)
i=i+1
x3=x2-f(x2)(x2-x1)/(f(x2)-f(x1))

Output root xi+1


Stop

You might also like