Computer Based Numerical & Statistical Techniques using 'C

Embed Size (px)

Citation preview

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    1/35

    Term Work

    On

    Computer Based Numerical &Statistical Techniques

    (Phase II)

    April 10,2012 to March 18,2012

    Program no. Date Program Name Remarks

    1 10-04012 Write a Program in C to implement X,R,C,P Charts

    2 20-04012 Write a Program in C to find value of function UsingNewton Forward Interpolation.

    3 24-04-12 Write a Program in C to find value of function UsingNewton Backward Interpolation

    4 27-04-12 Write a Program in C to find value of function UsingGauss Forward Interpolation.

    5 27-04-12 Write a Program in C to find value of function Using

    Gauss backward Interpolation

    6 01-04-12 Write a Program in C to find value of function UsingLangrange Interpolation

    7 04-04012 Write a Program in C to find value of function UsingNewton Divided Difference Formula

    8 08-04-12 Write a Program in C to find value of function UsingNewton Divided Difference Formula

    9 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 usingSimpson3/8 Rule

    Group Name: G1

    Group Teacher: Tarun Kathuria

    Signature:

    Class Teacher: Tarun Kathuria

    Signature:

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    2/35

    //Program to implement X Chart

    //Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date: 10-04-12

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    3/35

    OUTPUT:

    How many samples are there:25

    Enter the average observation each:

    For Sample 1:15.91

    For Sample 2:15.99For 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.96For 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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    4/35

    //Program to implement R chart

    //Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date: 10-04-12

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    5/35

    OUTPUT:

    How many samples are there:25

    Enter the Range:

    For Sample 1:0.19

    For Sample 2:0.27For 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.43For 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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    6/35

    //Program to implement P chart

    //Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date: 10-04-12

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    7/35

    OUTPUT:

    How many samples are there:20

    Enter the number of defective tyres:

    For Sample 1:3

    For Sample 2:2

    For Sample 3:1For 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:2For 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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    8/35

    //Program to implement C chart

    //Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date: 10-04-12

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    9/35

    OUTPUT:

    Enter the number of complaints:

    For Week 1:3

    For Week 2:2

    For Week 3:3For Week 4:1

    For Week 5:3

    For Week 6:3

    For Week 7:3

    For Week 8:2

    For Week 9:1

    For Week 10:3

    For Week 11:3

    For Week 12:4

    For Week 13:2For Week 14:1

    For Week 15:1

    For Week 16:1

    For Week 17:3

    For Week 18:2

    For Week 19:2

    For Week 20:3

    Enter the value of Z:3

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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    10/35

    //Program to find the value using Newton Forward Method

    //Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date:20-04-12

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    11/35

    }

    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;

    }

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    12/35

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    13/35

    //Program to find the value using Newton Backward Method

    //Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date:24-04-12

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    14/35

    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;

    }

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    15/35

    OUTPUT:

    Enter the value of n:5

    X Y

    1891 46

    1901 661911 81

    1921 93

    1931 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 2.001931.00 101.00 8.00 -4.00 -1.00 -3.00

    Enter the value of x:1925

    The value of f(1925.00)is:99.92

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    16/35

    //Program to find the value using Gauss Forward Method

    // Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date:27-04-1

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    17/35

    }

    u=(x1-x0)/h;

    printf("\nTaking the origin at %f \n",u);

    index=n/2;

    for(i=0;i=1)

    {

    fact=fact*a;

    a--;

    }

    return fact;

    }

    float fun(float u,int i)

    {

    if(i

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    18/35

    OUTPUT:

    Enter the value of n:5

    X Y

    21 18.4708

    25 17.814429 17.1070

    33 16.3432

    37 15.5154

    **Forward difference table**

    21.00 18.47 -0.66 -0.05 -0.01 -0.00

    25.00 17.81 -0.71 -0.06 -0.01

    29.00 17.11 -0.76 -0.06

    33.00 16.34 -0.8337.00 15.52

    Enter the value of x:30

    Taking the origin at 0.250000

    The value of f(30.00)is:16.92160

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    19/35

    //Program to find the value using Gauss Backward Method

    //Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date:27-04-12

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    20/35

    }

    u=(x1-x0)/h;

    printf("\nTaking the origin at %f \n",x0);

    index=n/2;

    for(i=0;i=1)

    {

    fact=fact*a;

    a--;

    }

    return fact;

    }

    float fun(float u,int i)

    {

    if(i

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    21/35

    OUTPUT:

    Enter the value of n:4

    X Y

    12500 111.80339912510 111.848111

    12520 111.892806

    12530 111.937483

    **Backward difference table**

    12500.00 111.80

    12510.00 111.85 0.04

    12520.00 111.89 0.04 -0.00

    12530.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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    22/35

    //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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    23/35

    OUTPUT:

    Enter the number of terms:4

    Enter the values of x:7

    8

    9

    10Enter 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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    24/35

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

    //Ashish Ruhela

    //MCA 2 A

    //Roll No. : 10

    //Date:04-04-12

    #include

    #include

    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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    25/35

    z=1.0;

    for(j=0;j

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    26/35

    OUTPUT:

    Enter the value of n:6

    X Y

    4 48

    5 1007 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.0010.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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    27/35

    //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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    28/35

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    29/35

    OUTPUT:

    Enter the limit:

    Enter the upper limit:1

    Enter the lower limit:0

    Enter the no. of subintervals:5

    x f(x)

    0.00 0.000

    0.20 0.008

    0.40 0.064

    0.60 0.216

    0.80 0.512

    1.00 1.000

    Result is:0.260000

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    30/35

    //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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    31/35

    }

    res=h/3*(res+eve+odd);

    printf("\n\nResult is:%f",res);

    getch(); }

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    32/35

    OUTPUT:

    Enter the limit:

    Enter the upper limit:6

    Enter the lower limit:0

    Enter the no. of subintervals:6

    x f(x)

    0.00 1.000

    1.00 0.500

    2.00 0.200

    3.00 0.100

    4.00 0.0595.00 0.038

    6.00 0.027

    Result is:1.366174

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    33/35

    //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

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    34/35

    }

    res=3*h/8*(res+eve+odd);

    printf("\n\nResult is:%f",res);

    getch(); }

  • 7/31/2019 Computer Based Numerical & Statistical Techniques using 'C'

    35/35

    OUTPUT:

    Enter the limit:

    Enter the upper limit:6

    Enter the lower limit:0

    Enter the no. of subintervals:6

    x f(x)

    0.00 1.000

    1.00 0.500

    2.00 0.200

    3.00 0.100

    4.00 0.059

    5.00 0.0386.00 0.027

    Result is:1.357081