Вы находитесь на странице: 1из 35

Term Work

On
Computer Based Numerical &
Statistical Techniques
(Phase II)
April 10,2012 to March 18,2012

Program no.

Date

Program Name

10-04012

Write a Program in C to implement X,R,C,P Charts

20-04012

Write a Program in C to find value of function Using


Newton Forward Interpolation.

24-04-12

27-04-12

Write a Program in C to find value of function Using


Newton Backward Interpolation
Write a Program in C to find value of function Using
Gauss Forward Interpolation.

27-04-12

Write a Program in C to find value of function Using


Gauss backward Interpolation

01-04-12

Write a Program in C to find value of function Using


Langrange Interpolation

04-04012

Write a Program in C to find value of function Using


Newton Divided Difference Formula

08-04-12

Write a Program in C to find value of function Using


Newton Divided Difference Formula

11-04-12

Write a Program in C to find value of Integration using


Simpson1/3 Rule

10

15-04-12

Write a Program in C to find value of Integration using


Simpson3/8 Rule

Group Name: G1
Group Teacher: Tarun Kathuria
Signature:
Class Teacher: Tarun Kathuria
Signature:

Remarks

//Program to implement X Chart


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date: 10-04-12
#include<math.h>
void main()
{
float x[30],cl,ucl,lcl,sum=0.0,sd,sd1;
int i,n,z;
clrscr();
printf("\nHow many samples are there:");
scanf("%d",&n);
printf("\n\nEnter the average observation each:\n\n");
for(i=0;i<n;i++)
{
printf("For Sample %d:",i+1);
scanf("%f",&x[i]);
sum+=x[i];
}
printf("\nEnter the value of z:(Standard Normal Variable)");
scanf("%d",&z);
printf("\nEnter the standard deviation:");
scanf("%f",&sd);
cl=sum/n;
sd1=sd/sqrt(n);
ucl=cl+z*sd1;
lcl=cl-z*sd1 ;
printf("\nU.C.L=%f C.L=%f L.C.L=%f",ucl,cl,lcl);
getch();
}

OUTPUT:
How many samples are there:25
Enter the average observation each:
For Sample 1:15.91
For Sample 2:15.99
For Sample 3:15.92
For Sample 4:15.93
For Sample 5:15.98
For Sample 6:16.03
For Sample 7:15.96
For Sample 8:15.93
For Sample 9:15.96
For Sample 10:15.83
For Sample 11:15.99
For Sample 12:15.96
For Sample 13:15.83
For Sample 14:15.91
For Sample 15:16.05
For Sample 16:15.99
For Sample 17:15.86
For Sample 18:16.01
For Sample 19:15.98
For Sample 20:16.02
For Sample 21:16.00
For Sample 22:15.90
For Sample 23:15.86
For Sample 24:15.94
For Sample 25:15.94
Enter the value of z:(Standard Normal Variable):3
Enter the standard deviation:0.14
U.C.L=16.159100 C.L=15.950000 L.C.L=15.739100

//Program to implement R chart


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date: 10-04-12
#include<math.h>
void main()
{
float r[30],cl,ucl,lcl,sum=0.0;
int i,n,d3,d4;
clrscr();
printf("\nHow many samples are there:");
scanf("%d",&n);
printf("\nEnter the Range:\n");
for(i=0;i<n;i++)
{
printf("For Sample %d:",i+1);
scanf("%f",&r[i]);
sum+=r[i];
}
printf("\nEnter the value of d3:");
scanf("%d",&d3);
printf("\nEnter the value of d4:");
scanf("%d",&d4);
cl=sum/n;
ucl=d4*cl;
lcl=d3*cl;
if(lcl<0)
lcl=0.0;
printf("\nU.C.L=%f C.L=%f L.C.L=%f",ucl,cl,lcl);
getch();
}

OUTPUT:
How many samples are there:25
Enter the Range:
For Sample 1:0.19
For Sample 2:0.27
For Sample 3:0.17
For Sample 4:0.46
For Sample 5:0.47
For Sample 6:0.20
For Sample 7:0.46
For Sample 8:0.20
For Sample 9:0.21
For Sample 10:0.30
For Sample 11:0.29
For Sample 12:0.43
For Sample 13:0.24
For Sample 14:0.37
For Sample 15:0.31
For Sample 16:0.29
For Sample 17:0.33
For Sample 18:0.34
For Sample 19:0.28
For Sample 20:0.20
For Sample 21:0.23
For Sample 22:0.16
For Sample 23:0.32
For Sample 24:0.15
For Sample 25:0.30
Enter the value of d3:0
Enter the value of d4:2.28
U.C.L=0.598756 C.L=0.289671 L.C.L=0.000000

//Program to implement P chart


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date: 10-04-12
#include<math.h>
void main()
{
float x[30],y[30],cl,ucl,lcl,q,w,sum=0.0,obs=1.0;
int i,n,z;
clrscr();
printf("\nHow many samples are there:");
scanf("%d",&n);
printf("\n\nEnter the number of defective tyres:\n\n");
for(i=0;i<n;i++)
{
printf("For Sample %d:",i+1);
scanf("%f",&x[i]);
sum+=x[i];
}
printf("Enter the value of z:");
scanf("%d",&z);
printf("\nEnter the number of observations each for %d
samples:",n);
scanf("%f",&obs);
obs=obs*n;
cl=sum/obs;
q=1.0-cl;
w=sqrt((cl*q)/n);
ucl=cl+z*w;
lcl=cl-z*w;
if(lcl<0)
lcl=0.0;
printf("\nU.C.L=%f C.L=%f L.C.L=%f",ucl,cl,lcl);
getch();
}

OUTPUT:
How many samples are there:20
Enter the number of defective tyres:
For Sample 1:3
For Sample 2:2
For Sample 3:1
For Sample 4:2
For Sample 5:1
For Sample 6:3
For Sample 7:3
For Sample 8:2
For Sample 9:1
For Sample 10:2
For Sample 11:3
For Sample 12:2
For Sample 13:2
For Sample 14:1
For Sample 15:1
For Sample 16:2
For Sample 17:4
For Sample 18:3
For Sample 19:1
For Sample 20:1
Enter the value of z:3
Enter the number of observations each for 20 samples:20
U.C.L=0.301246 C.L=0.100000 L.C.L=0.000000

//Program to implement C chart


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date: 10-04-12
#include<math.h>
void main()
{
float x[30],y[30],cl,ucl,lcl,sum=0.0;
int i,n,z;
clrscr();
printf("\nHow many weeks are monitored:");
scanf("%d",&n);
printf("\n\nEnter the number of complaints:\n\n");
for(i=0;i<n;i++)
{
printf("For Week %d:",i+1);
scanf("%f",&x[i]);
sum+=x[i];
}
printf("\nEnter the value of Z:");
scanf("%d",&z);
cl=sum/n;
ucl=cl+z*sqrt(cl);
lcl=cl-z*sqrt(cl);
if(lcl<0)
lcl=0.0;
printf("\nU.C.L=%f C.L=%f L.C.L=%f",ucl,cl,lcl);
getch();
}

OUTPUT:
Enter the number of complaints:
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For
For

Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week
Week

1:3
2:2
3:3
4:1
5:3
6:3
7:3
8:2
9:1
10:3
11:3
12:4
13:2
14:1
15:1
16:1
17:3
18:2
19:2
20:3

Enter the value of Z:3


U.C.L=6.849725 C.L=2.300000 L.C.L=0.000000

//Program to find the value using Newton Forward Method


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date:20-04-12
#include<math.h>
void main()
{
float x[10],y[10][10],x1,h,r=0.0,z;
int i,j,n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
printf("\n X
Y \n");
for(i=0;i<n;i++)
{
scanf("%f %f",&x[i],&y[i][0]);
}
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
y[j][i]=y[j+1][i-1]-y[j][i-1];
}
}
printf("\n\n");
printf("**Forward difference table**\n");
for(i=0;i<n;i++)
{
printf(" %.2f ",x[i]);
for(j=0;j<n-i;j++)
{
printf(" %.2f ",y[i][j]);
}
printf("\n");
}
printf("\nEnter the value of x:");
scanf("%f",&x1);
h=x[1]-x[0];
for(i=0;i<n;i++)
{
z=1.0;
for(j=0;j<i;j++)
{
z=z*(x1-x[j]);
}
r+=y[0][i]*z/(pow(h,i)*fact(i));

}
printf("\nThe value of f(%.2f)is:%.5f",x1,r);
getch();
}
int fact(int a)
{
int fact=1;
while(a>=1)
{
fact=fact*a;
a--;
}
return fact;
}

OUTPUT:
Enter the value of n:4
X
45
50
55
60

Y
.7071
.7660
.8192
.8660

**Forward difference table**


45.00 0.71 0.06 -0.01 -0.00
50.00 0.77 0.05 -0.01
55.00 0.82 0.05
60.00 0.87
Enter the value of x:52
The value of f(52.00)is:0.78800

//Program to find the value using Newton Backward Method


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date:24-04-12
#include<math.h>
void main()
{
float x[10],y[10][10],x1,h,z,r=0.0,k;
int i,j,n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
printf("\nX Y \n");
for(i=0;i<n;i++)
{
scanf("%f %f",&x[i],&y[i][0]);
}
for(i=1;i<n;i++)
{
for(j=n-1;j>(i-1);j--)
{
y[j][i]=y[j][i-1]-y[j-1][i-1];
}
}
printf("\n\n");
printf("**Backward difference table**\n");
for(i=0;i<n;i++)
{
printf(" %.2f ",x[i]);
for(j=0;j<=i;j++)
{
printf(" %.2f ",y[i][j]);
}
printf("\n");
}
printf("\nEnter the value of x:");
scanf("%f",&x1);
h=x[1]-x[0];
k=0;
for(i=n-1;i>=0;i--)
{
z=1.0;
for(j=n-1;j>i;j--)
{
z=z*(x1-x[j]);
}

r+=y[n-1][k]*z/(pow(h,k)*fact(k));
k++;
}
printf("\nThe value of f(%.2f)is:%.2f",x1,r);
getch();
}
int fact(int a)
{
int fact=1;
while(a>=1)
{
fact=fact*a;
a--;
}
return fact;
}

OUTPUT:
Enter the value of n:5
X Y
1891
1901
1911
1921
1931

46
66
81
93
101

**Backward difference table**


1891.00 46.00
1901.00 66.00 20.00
1911.00 81.00 15.00 -5.00
1921.00 93.00 12.00 -3.00
1931.00 101.00 8.00 -4.00

2.00
-1.00

Enter the value of x:1925


The value of f(1925.00)is:99.92

-3.00

//Program to find the value using Gauss Forward Method


// Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date:27-04-1
#include<math.h>
void main()
{
float x[10],y[10][10],x1,h,r=0.0,z,u,x0;
int i,j,n,index,c=0;
float fun(float,int);
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
printf("\n X
Y \n");
for(i=0;i<n;i++)
{
scanf("%f %f",&x[i],&y[i][0]);
}
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
{
y[j][i]=y[j+1][i-1]-y[j][i-1];
}
}
printf("\n\n");
printf("**Forward difference table**\n");
for(i=0;i<n;i++)
{
printf(" %.2f ",x[i]);
for(j=0;j<n-i;j++)
{
printf(" %.2f ",y[i][j]);
}
printf("\n");
}
printf("\nEnter the value of x:");
scanf("%f",&x1);
h=x[1]-x[0];
for(i=0;i<n;i++)
{
if((x1-x[i])<=h)
{
x0=x[i];
break;
}

}
u=(x1-x0)/h;
printf("\nTaking the origin at %f \n",u);
index=n/2;
for(i=0;i<n;i++)
{
z=fun(u,i);
r+=y[index][i]*z/fact(i);
c++;
if(c%2==0)
index--;
}
printf("\nThe value of f(%.2f)is:%.5f",x1,r);
getch();
}
int fact(int a)
{
int fact=1;
while(a>=1)
{
fact=fact*a;
a--;
}
return fact;
}
float fun(float u,int i)
{
if(i<1)
{
return 1;
}
else if(i==1)
return u;
else if(i%2==0)
{
return((u-i/2)*fun(u,i-1));
}
else
{
return((u+i/2)*fun(u,i-1));
}
}

OUTPUT:
Enter the value of n:5
X
21
25
29
33
37

Y
18.4708
17.8144
17.1070
16.3432
15.5154

**Forward difference table**


21.00 18.47 -0.66 -0.05 -0.01
25.00 17.81 -0.71 -0.06 -0.01
29.00 17.11 -0.76 -0.06
33.00 16.34 -0.83
37.00 15.52
Enter the value of x:30
Taking the origin at 0.250000
The value of f(30.00)is:16.92160

-0.00

//Program to find the value using Gauss Backward Method


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date:27-04-12
#include<math.h>
void main()
{
float x[10],y[10][10],x1,h,r=0.0,z,u,x0;
int i,j,n,index,c=1;
float fun(float,int);
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
printf("\n X
Y \n");
for(i=0;i<n;i++)
{
scanf("%f %f",&x[i],&y[i][0]);
}
for(i=1;i<n;i++)
{
for(j=n-1;j>i-1;j--)
{
y[j][i]=y[j][i-1]-y[j-1][i-1];
}
}
printf("\n\n");
printf("**Backward difference table**\n");
for(i=0;i<n;i++)
{
printf(" %.2f ",x[i]);
for(j=0;j<=i;j++)
{
printf(" %.2f ",y[i][j]);
}
printf("\n");
}
printf("\nEnter the value of x:");
scanf("%f",&x1);
h=x[1]-x[0];
for(i=n-1;i>1;i--)
{
if((x[i]-x1)<h)
{
x0=x[i];
break;
}

}
u=(x1-x0)/h;
printf("\nTaking the origin at %f \n",x0);
index=n/2;
for(i=0;i<n;i++)
{
z=fun(u,i);
r+=y[index][i]*z/fact(i);
c++;
if(c%2==0)
index--;
}
printf("\nThe value of f(%.2f)is:%.5f",x1,r);
getch();
}
int fact(int a)
{
int fact=1;
while(a>=1)
{
fact=fact*a;
a--;
}
return fact;
}
float fun(float u,int i)
{
if(i<1)
{
return 1;
}
else if(i==1)
return u;
else if(i%2==0)
{
return((u+i/2)*fun(u,i-1));
}
else
{
return((u-i/2)*fun(u,i-1));
}
}

OUTPUT:
Enter the value of n:4
X
12500
12510
12520
12530

Y
111.803399
111.848111
111.892806
111.937483

**Backward
12500.00
12510.00
12520.00
12530.00

difference table**
111.80
111.85 0.04
111.89 0.04 -0.00
111.94 0.04 -0.00

0.00

Enter the value of x:12516


Taking the origin at 12520.000000
The value of f(12516.00)is:111.87492

//Program to find the value using Lagrange's Method


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date:01-05-12
void main()
{
float x[30],y[30],x1,sum=0,s1,s2;
int n,i,j;
clrscr();
printf("\n Enter the number of terms:");
scanf("%d",&n);
printf("\n\nEnter the values of x:");
for(i=0;i<n;i++)
{
scanf("%f",&x[i]);
}
printf("\n\nEnter the values of y:");
for(i=0;i<n;i++)
{
scanf("%f",&y[i]);
}
printf("\n\n Enter the value of x,for which you find the value
of y:");
scanf("%f",&x1);
for(i=0;i<n;i++)
{
s1=1;
s2=1;
for(j=0;j<n;j++)
{
if(j!=i)
{
s1=s1*(x1-x[j]);
s2=s2*(x[i]-x[j]);
}
}
sum=sum+((s1/s2)*y[i]);
}
printf(" Value of y is %f",sum);
getch();
}

OUTPUT:
Enter the number of terms:4
Enter the values of x:7
8
9
10
Enter the values of y:3
1
1
9
Enter the value of x,for which you find the value of y:9.5
Value of y is 3.625000

//Program to find the value using Newton divided difference formula


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date:04-04-12
#include<math.h>
#include<stdlib.h>
void main()
{
float x[10],y[10][10],x1,z,r=0.0;
int i,j,n,k=0,m=0;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
printf("\n X
Y \n");
for(i=0;i<n;i++)
{
scanf("%f %f",&x[i],&y[i][0]);
}
printf("\n\n");
printf("**Divided difference table**\n");
for(i=1;i<n;i++)
{
k=m+1;
for(j=0;j<n-i;j++)
{
y[j][i]=((y[j+1][i-1]-y[j][i-1])/(x[k]-x[j]));
k++;
}
m++;
}
for(i=0;i<n;i++)
{
printf(" %.2f ",x[i]);
for(j=0;j<n-i;j++)
{
printf(" %.2f ",y[i][j]);
}
printf("\n");
}
printf("\nEnter the value at which you want to find the
function:");
scanf("%f",&x1);
r=y[0][0];
k=1;
for(i=0;i<n-1;i++)
{

z=1.0;
for(j=0;j<=i;j++)
{
z=z*(x1-x[j]);
}
r=r+z*y[0][k];
k++;
}
printf("\n The value of f(%.3f) is: %.3f",x1,r);
getch();
}

OUTPUT:
Enter the value of n:6
X
Y
4 48
5 100
7 294
10 900
11 1210
13 2028

**Divided difference table**


4.00 48.00 52.00 15.00 1.00 0.00 0.00
5.00 100.00 97.00 21.00 1.00 0.00
7.00 294.00 202.00 27.00 1.00
10.00 900.00 310.00 33.00
11.00 1210.00 409.00
13.00 2028.00
Enter the value at which you want to find the function:8
The value of f(8.000) is: 448.000

//Program to evaluate the given function using Trapezoidal rule


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date: 08-05-12
#define f(x) ((x)*(x)*(x))
void main()
{
int ub,lb,j=0;
float x[20],y[20],h,n,i,res;
aa:
printf("\nEnter the limit:\n");
printf("\nEnter the upper limit:");
scanf("%d",&ub);
printf("Enter the lower limit:");
scanf("%d",&lb);
if(ub<lb)
{
printf("Upper limit must be greater than lower limit");
getch();
goto aa;
}
printf("\nEnter the no. of subintervals:");
scanf("%f",&n);
h=(ub-lb)/n;
for(i=lb;i<=ub;i+=h)
{
x[j]=i;
y[j]=f(i);
j++;
}
printf("\n x
f(x)\n");
for(i=0;i<j;i++)
{
printf("\n %.2f
%.3f",x[i],y[i]);
}
res=(y[0]+y[j-1]);
for(i=1;i<j-1;i++)
{
res=res+2*y[i];
}
res=h/2*res;
printf("\n\nResult is:%f",res);
getch();
}

OUTPUT:
Enter the limit:
Enter the upper limit:1
Enter the lower limit:0
Enter the no. of subintervals:5
x
0.00
0.20
0.40
0.60
0.80
1.00

f(x)
0.000
0.008
0.064
0.216
0.512
1.000

Result is:0.260000

//Program to Evaluate the given function using Simpson's 1/3 rule


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date: 11-05-12
#define f(x) (1/(1+(x)*(x)))
void main()
{
int ub,lb,j=0,k;
float x[20],y[20],h,n,res,eve,odd,i;
aa:
printf("\nEnter the limit:\n");
printf("\nEnter the upper limit:");
scanf("%d",&ub);
printf("Enter the lower limit:");
scanf("%d",&lb);
if(ub<lb)
{
printf("Upper limit must be greater than lower limit");
getch();
goto aa;
}
printf("\nEnter the no. of subintervals:");
scanf("%f",&n);
h=(ub-lb)/n;
for(i=lb;i<=ub;i+=h)
{
x[j]=i;
y[j]=f(i);
j++;
}
printf("\n x
f(x)\n");
for(i=0;i<j;i++)
{
printf("\n %.2f
%.3f",x[i],y[i]);
}
res=(y[0]+y[j-1]);
for(k=1;k<j-1;k++)
{
if(k%2==0)
{
eve=eve+2*y[k];
}
else
{
odd=odd+4*y[k];
}

}
res=h/3*(res+eve+odd);
printf("\n\nResult is:%f",res);
getch(); }

OUTPUT:
Enter the limit:
Enter the upper limit:6
Enter the lower limit:0
Enter the no. of subintervals:6
x
0.00
1.00
2.00
3.00
4.00
5.00
6.00

f(x)
1.000
0.500
0.200
0.100
0.059
0.038
0.027

Result is:1.366174

//Program to Evaluate the given function using Simpson's 3/8 rule


//Ashish Ruhela
//MCA 2 A
//Roll No. : 10
//Date: 15-05-12
#define f(x) (1/(1+(x)*(x)))
void main()
{
int ub,lb,j=0,k;
float x[20],y[20],h,n,res,eve,odd,i;
aa:
printf("\nEnter the limit:\n");
printf("\nEnter the upper limit:");
scanf("%d",&ub);
printf("Enter the lower limit:");
scanf("%d",&lb);
if(ub<lb)
{
printf("Upper limit must be greater than lower limit");
getch();
goto aa;
}
printf("\nEnter the no. of subintervals:");
scanf("%f",&n);
h=(ub-lb)/n;
for(i=lb;i<=ub;i+=h)
{
x[j]=i;
y[j]=f(i);
j++;
}
printf("\n x
f(x)\n");
for(i=0;i<j;i++)
{
printf("\n %.2f
%.3f",x[i],y[i]);
}
res=(y[0]+y[j-1]);
for(k=1;k<j-1;k++)
{
if(k%3==0)
{
eve=eve+2*y[k];
}
else
{
odd=odd+3*y[k];
}

}
res=3*h/8*(res+eve+odd);
printf("\n\nResult is:%f",res);
getch(); }

OUTPUT:
Enter the limit:
Enter the upper limit:6
Enter the lower limit:0
Enter the no. of subintervals:6
x
0.00
1.00
2.00
3.00
4.00
5.00
6.00

f(x)
1.000
0.500
0.200
0.100
0.059
0.038
0.027

Result is:1.357081

Вам также может понравиться