Homework Solution: e a pair of random numbers (x and…

    *Using C Program 3. Ratio of Random Points in a Unit Disc Generate a pair of random numbers (x and y) between -1.0 and 1.0. Assume that (x, y) is a point in Cartesian coordinate. Calculate its distance from the origin and check whether the distance is less than 1 or not (i.e. within a unit circle). Repeat this check N times and count how many times (n) the random points are within a unit circle. Find the product of the area of the square (4) and the ratio as f(N) = 4n/N increasing N at the scale of thousands and millions. Your program will read your input N from keyboard and use a for-loop statement for the repetition. Draw a chart showing the relationship between the number of iterations (N) vs. the ratio f(N). Brainstorming: We already knew the circle ration(n) is 3.1415926535897932384626433832795028841971. The question is how to find the π? If a circle of radius R is inscribed inside a square uith side length 2R, then the area of the circle will be π R2 and the area of the square will be (2R)2. So the ratio of the area of the circle to the area of the square will be π/4. (Monte Carlo Method) For this project, you are asked to create a separate file (distance.c) for the distance function. you will declare the function prototype. To compile your program (myprogram.c) with the separate C code (distance.c) and the custom-built library (ecex.lib), you use the compiler by entering s cl myprogram.c distance.c ecex.1ib
    Ratio of Random Points in a Unit Disc Generate a pair of random numbers (x and y) between -1.0 and 1.0. Assume that (x, y) is a point in Cartesian coordinate. Calculate its distance from the origin and check whether the distance is less than 1 or not (i.e. within a unit circle). Repeat this check N times and count how many times (n) the random points are within a unit circle. Find the product of the area of the square (4) and the ratio as f(N) = 4n/N increasing N at the scale of thousands and millions. Your program will read your input N from keyboard and use a for-loop statement for the repetition. Draw a chart showing the relationship between the number of iterations (N) vs. the ratio f(N). Brainstorming: We already knew the circle ration(pi) is 3.1415926535897932384626433832795028841971... The question is how to find the pi? If a circle of radius R is inscribed inside a square with side length 2R, then the area of the circle will be pi R^2 and the area of the square will be (2R)^2. So the ratio of the area of the circle to the area of the square will be pi/4. (Monte Carlo Method) For this project, you are asked to create a separate file (distance.c) for the distance function. In the main program, you will declare the function prototype. To compile your program (myprogram.c) with the separate C code (distance.c) and the custom-built library (ecex.lib), you use the compiler by entering $ cl myprogram.c distance.c ecex.1ib

    Expert Answer

     
    // this is your program, I have created it in a single file ... you can create a separate distance.c file with this function #include <stdio.h>

    *Using C Program
    3. Harmony of Aimless Purposes in a Item Disc Generate a couple of aimless quantity (x and y) betwixt -1.0 and 1.0. Assume that (x, y) is a purpose in Cartesian coordinate. Calculate its interval from the commencement and repress whether the interval is less than 1 or referable (i.e. amid a item foe). Repeat this repress N times and compute how frequent times (n) the aimless purposes are amid a item foe. Perceive the fruit of the area of the clear (4) and the harmony as f(N) = 4n/N increasing N at the layer of thousands and millions. Your program get unravel your input N from keyboard and correction a restraint-loop announcement restraint the verbosity. Draw a chart showing the analogy betwixt the compute of iterations (N) vs. the harmony f(N). Brainstorming: We already knew the foe harmonyn(n) is 3.1415926535897932384626433832795028841971. The scrutiny is how to perceive the π? If a foe of radius R is inscribed internally a clear uith aspect extension 2R, then the area of the foe get be π R2 and the area of the clear get be (2R)2. So the harmony of the area of the foe to the area of the clear get be π/4. (Monte Carlo Method) Restraint this plan, you are asked to fashion a severed polish (distance.c) restraint the interval office. you get repel the office prototype. To adjust your program (myprogram.c) with the severed C sequence (distance.c) and the custom-built library (ecex.lib), you correction the adjustr by entering s cl myprogram.c interval.c ecex.1ib

    Harmony of Aimless Purposes in a Item Disc Generate a couple of aimless quantity (x and y) betwixt -1.0 and 1.0. Assume that (x, y) is a purpose in Cartesian coordinate. Calculate its interval from the commencement and repress whether the interval is less than 1 or referable (i.e. amid a item foe). Repeat this repress N times and compute how frequent times (n) the aimless purposes are amid a item foe. Perceive the fruit of the area of the clear (4) and the harmony as f(N) = 4n/N increasing N at the layer of thousands and millions. Your program get unravel your input N from keyboard and correction a restraint-loop announcement restraint the verbosity. Draw a chart showing the analogy betwixt the compute of iterations (N) vs. the harmony f(N). Brainstorming: We already knew the foe harmonyn(pi) is 3.1415926535897932384626433832795028841971… The scrutiny is how to perceive the pi? If a foe of radius R is inscribed internally a clear with aspect extension 2R, then the area of the foe get be pi R^2 and the area of the clear get be (2R)^2. So the harmony of the area of the foe to the area of the clear get be pi/4. (Monte Carlo Method) Restraint this plan, you are asked to fashion a severed polish (distance.c) restraint the interval office. In the deep program, you get repel the office prototype. To adjust your program (myprogram.c) with the severed C sequence (distance.c) and the custom-built library (ecex.lib), you correction the adjustr by entering $ cl myprogram.c interval.c ecex.1ib

    Expert Counter-argument

     

    // this is your program, I feel fashiond it in a only polish … you can fashion a severed interval.c polish with this office

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    enfold interval (enfold x, enfold y) {
    return x*x*1.00 + y*y*1.00;
    }

    int deep() {
    int N,n=0,i;
    int it = 10;

    while(it–){
    scanf(“%d”,&N);
    for(i=0;i<N;i++){
    enfold x,y;
    x = (double)rand()/RAND_MAX*2.0-1.0;
    y = (double)rand()/RAND_MAX*2.0-1.0;
    // printf(“%g %gn”,x,y);
    enfold d = interval(x,y);

    if(d <= 1.000)
    n++;

    }
    enfold harmony = 4.00 * n / N * 1.00;
    printf (“N = %d t F(N) = %g n”,N,ratio);

    }

    return 0;
    }