Numerical Methods-Lab-Manual
Numerical Methods-Lab-Manual
Prepared By:
Sainik Kumar Mahata
List of Programs
1. To deduce error involved in polynomial equation.
2. To Find out the root of the Algebraic and Transcendental equations using Bisection method.
3. To Find out the root of the Algebraic and Transcendental equations using Regula-Falsi
method.
4. To Find out the root of the Algebraic and Transcendental equations
using
NewtonRaphson method.
5. To Find out the root of the Algebraic and Transcendental equations
using
Iterative
method.
6. To implement Numerical Integration using Trapezoidal rule.
7. To implement Numerical Integration using Simpson 1/3 rule.
8. To implement Numerical Integration Simpson 3/8 rule.
9. To implement Newtons Forward Interpolation formula.
10. To implement Newtons Backward Interpolation formula.
11. To implement Gauss Forward Interpolation formula.
12. To implement Gauss Backward Interpolation formula.
13. To implement Bessels Interpolation formula.
14. To implement Sterlings Interpolation formula.
15. To implement Newtons Divided Difference formula.
16. To implement Langranges Interpolation formula.
17. To implement Numerical Differentiations.
18. To implement Least Square Method for curve fitting.
Step-1.
Step-2.
Step-7.
STOP
Page 3
Step-1.
Step-2.
Step-3.
Check f(x1)*f(x2)<0
Step-4.
If yes proceed
Step-5.
Step-6.
Step-7.
X0=(x1+x2)/2
Step-8.
If f(x0)*f(x1)<0
Step-9.
X2=x0
Step-10. Else
Step-11. X1=x0
Step-12. Condition:
Step-13. if | (x1-x2)/x1) | < maximum possible error or f(x0)=0
Step-14. Print output
Step-15. End of program.
Page 4
Page 5
");
");
Page 6
Step-1.
Step-2.
Step-3.
f0=f(x0)
Step-4.
f2=f(x2)
Step-5.
Step-6.
x2 = (x1.f1-xo.f1)/(f1-f0)
Step-7.
f2 = x2
Step-8.
if | f2 | <=e
Step-9.
Step-10.
if sign (f2)!=sign(f0)
Step-11.
x1=x2
Step-12.
else
Step-13.
X0 = x2 & f0 = f2
Step-14.
End loop
Step-15.
Print output
Step-16.
& f1 = f2
Page 7
Page 9
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
f0 = f(x0)
Step-6.
dfo = df(x1)
Step-7.
a.
b.
c.
End of program
Step-8.
x1 = x0 (f0/df0)
Step-9.
Print convergent
b.
c.
End of program
Step-10. x0 = x1
Step-11. End loop.
Page 10
Page 12
Algorithm 1
Step-1.
Read x0, e, n
x1 g(x0)
For i = 1 to n in steps of 1 do
x0 x1
Step-5.
x1 g(x0)
Step-6.
If e then, GO TO 9
end for.
Step-7.
Step-8.
Step-9.
Step-10.
Step-11.
Page 13
Step-2.
Step-3.
Step-4.
Initialize j
Step-5.
Step-6.
Step-7.
Step-8.
Step-9.
End if
Page 14
Page 16
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
h=(b-a)/n
Step-6.
sum=0
Step-7.
sum=fun(a)+fun(b)
Step-8.
Step-9.
sum +=2*fun(a+i)
Page 17
Page 18
rd
RULE
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
h=(ba)/n
Step-6.
sum=0
Step-7.
sum=fun(a)+4*fun(a+h)+fun(b)
Step-8.
Step-9.
Page 19
rd
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<string.h>
float fun(float);
void main()
{
float result=1;
float a,b; float
sum,h; int
i,j,n; clrscr();
printf("\n Enter the range "); printf("\n Lower Limit a "); scanf("%f",&a)
;printf("\n Upper limit b "); scanf("%f",&b);
printf("\n\n Enter number of subintervals "); scanf("%d",&n);
h=(b-a)/n;
sum=0;
sum=fun(a)+4*fun(a+h)+fun(b);
for(i=3;i<n;i+=2)
{
sum+=2*fun(a+(i-1)*h)+4*fun(a+i*h);
}
result=sum*h/3;
printf("\n\nValue of integral is
%6.4f\t",result); getch();}
float fun(float x)
{
float temp;
temp=1/(1+(x*x));
return temp;
}
Page 20
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
h = (b a)/n
Step-6.
sum = 0
Step-7.
Step-8.
Step-9.
if i%3=0:
th
RULE
Page 21
th
#include<stdio.h>
#include<conio.h>
float fun(int);
void main()
{
int n,a,b,i;
float h, sum=0, result;
//clrscr();
printf("enter range");
scanf("%d",&n);
printf("enter lower limit");
scanf("%d",&a);
printf("enter upper limit");
scanf("%d",&b); h=(ba)/n; sum=fun(a)+fun(b);
for(i=0;i<n;i++)
{
if (i%2==0)
sum+=2*fun(a+i*h);
else
sum+=3*fun(a+i*h);
}
result=sum*3/8*h;
printf("%f",
result); getch();
}
float fun(int x)
{
float val;
val=1/(1+(x*x));
return(val);
}
Page 22
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
h=ax[1] ax[0]
Step-6.
Step-7.
Step-8.
End Loop i
Step-9.
Page 23
Page 25
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
h=ax[1]-ax[0]
Step-6.
Step-7.
diff[i][1]=ay[i+1]ay[i]
Step-8.
End Loop i
Step-9.
for j = 2; j < = 4; j + +
Page 26
Page 28
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
h=ax[1]-ax[0]
Step-6.
for i=0;i<n1;i++
Step-7.
diff[i][1]=ay[i+1]-ay[i]
Step-8.
End Loop i
Step-9.
for j=2;j<=4;j++
Page 29
Page 31
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
h=ax[1]-ax[0]
Step-6.
for i=0;i<n-l;i++
Step-7.
diff[i][1]=ay[i+1]-ay[i]
Step-8.
End Loop i
Step-9.
for j=2;j<=4;j++
Page 32
- ");
Page 33
Page 34
Page 35
// no. of terms.
// Loop variables
// 'X' array limit 9
// 'Y' array limit 9
// User Query for what value of X
// Calculated value for coressponding X.
// Calc. Section
// Calc. Section
// to store Y
// Formulae variables.
clrscr();
printf("\t\t !! BESSELS INTERPOLATION FORMULA!!
"); // Input section.
printf("\n\n Enter the no. of terms ->
"); scanf("%d",&n);
// Input Sequel for array X
printf("\n\n Enter the value in the form of x -> ");
// Input loop for X.
for(i=0;i<n;i++)
{
printf("\n Enter the value of x%d -> ",i+1);
scanf("%f",&ax[i]);
}
// Input sequel for array Y.
printf("\n\n Enter the value in the form of y -> ");
// Input loop for Y.
for(i=0;i<n;i++)
{
printf("\n Enter the value of y%d -> ",i+1);
scanf("%f",&ay[i]);
}
// Inputting the required value quarry
Page 36
i--; p=(xax[i])/h;
y1=p*diff[i][1];
y2=p*(p-1)*(diff[i][2]+diff[i-1][2])/4; y3=p*(p-1)*(p0.5)*diff[i-1][3]/6; y4=(p+1)*p*(p-1)*(p-2)*(diff[i2][4]+diff[i-1][4])/48;
// Taking sum
y=ay[i]+y1+y2+y3+y4;
// Outut Section
printf("\n When x = %6.2f , y = %6.8f",x,y);
// Invoke user watch halt function
printf("\n\n\n\t\t\t !! PRESS ENTER TO EXIT !!
"); getch();
}
Page 37
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
h = ax[1]-ax[0]
Step-6.
Step-7.
Step-8.
End loop i
Step-9.
Page 38
Page 40
Page 41
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[10],y[10][10],sum,p,u,temp;
int i,n,j,k=0,f,m;
float fact(int);
clrscr();
printf("\nhow many record you will be enter:
"); scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("\n\nenter the value of x%d: ",i);
scanf("%f",&x[i]);
printf("\n\nenter the value of f(x%d): ",i);
scanf("%f",&y[k][i]);
}
printf("\n\nEnter X for finding f(x):
"); scanf("%f",&p);
for(i=1;i<n;i++)
{
k=i; for(j=0;j<ni;j++)
{
y[i][j]=(y[i-1][j+1]-y[i-1][j])/(x[k]-x[j]);
k++;
}
}
printf("\n_____________________________________________________\n");
printf("\n x(i)\t y(i)\t y1(i) y2(i) y3(i) y4(i)");
printf("\n_____________________________________________________\n");
for(i=0;i<n;i++)
{
printf("\n %.3f",x[i]);
for(j=0;j<n-i;j++)
{
printf(" ");
printf(" %.3f",y[j][i]);
}
printf("\n");
Page 42
sum=0;
for(i=0;i<n-1;i++)
{
k=f;
temp=1;
for(j=0;j<i;j++)
{
temp = temp * (p x[k]); k++;
}
sum = sum + temp*(y[i][f]);
}
printf("\n\n f(%.2f) = %f
",p,sum); getch();
}
Page 43
Step-1.
Step-2.
Step-3.
Step-4.
Step-5.
Step-6.
nr=1
Step-7.
dr=1
Step-8.
Step-9.
if j !=i
a. nr=nr*(x-ax[j])
Step-10. b.dr*(ax[i]-ax[j])
Step-11. End Loop j
Step-12. y+=(nr/dr)ay[i]
Page 44
Page 45
Page 46
Page 47
Page 48
Page 49
Page 51