Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Depth Gauge Problem Liquids are often stored in elliptical storage tanks as

ID: 3766084 • Letter: T

Question

The Depth Gauge Problem Liquids are often stored in elliptical storage tanks as shown below. To measure the volume of liquid in the tank, a depth gauge (measuring stick) can be used. It is inserted into an opening at the top and the level of liquid on the gauge can be used to determine the amount of liquid in the tank.

The tank has width w, height h and length len (all in meters). In the example output shown below, we take w=8, h=4 and len=7. Your programs should work for any values of w, h and len, not just these specific values.

The assignment is divided into two parts.

Part 1:

In the first part of the assignment we look at inserting a measuring stick that is already calibrated in units of 10 centimeters. This measuring gauge can be inserted into an opening at the top of the tank and used to measure the depth of the liquid in the tank.

Your task will be to write a C program to produce a table of values showing the volume of liquid in the tank for each of the points on the gauge.

The output of your program (for the example above) should look like:

Depth 10 cm : Volume 1.188814 cubic meters

Depth 20 cm : Volume 3.336448 cubic meters

Depth 30 cm : Volume 5.992683 cubic meters

. . .

Depth 380 cm : Volume 172.547399 cubic meters

Depth 390 cm : Volume 174.657114 cubic meters

Depth 400 cm : Volume 175.743037 cubic meters

Methodology for Part 1:

If the tank has width W and height H (in centimeters), the focal radii of the cross section are A = W/2 and B = H/2. Then the equation of the ellipse is:

X2/A2 + Y2/B2 = 1

To find the volume at given depth you should compute the cross-sectional area of the tank for each given depth using a numerical integration algorithm such as the trapezoidal method. You must use a general integration function and apply it to this particular function. Do not write an integration function that is specific to this problem. Do not use an analytic solution to integrate the function. Then multiply this by the length of the tank.

Hint: It is probably easier to imagine the tank on its side so that the depth gauge is inserted horizontally. If you do this you must express the equation as a function of y and integrate that function.

Part 2:

The second part of the assignment is a variation on this. In this case the stick is not calibrated. We would like to calibrate it. Rather than calibrate it by equidistant markings, we calibrate it to show at what level the tank contains a certain volume of the liquid.

You are to write a C program that determines where the gauge should be marked (to the nearest millimeter) corresponding to volumes of 5, 10, 15, … cubic meters (up to the total volume of the tank).

The output of your program (for the example above) should look like:

Volume 5: Depth 26.54 cm

Volume 10: Depth 42.48 cm

Volume 15: Depth 56.08 cm

. . .

Volume 165: Depth 355.12 cm

Volume 170: Depth 370.52 cm

Volume 175: Depth 392.03 cm

Methodology for Part 2:

If we view the volume as a function of the position y, this problem reduces to the problem of finding a root of the equation V(y) = depth, for the various depths. While the function V(y) is not given by a simple formula, it can be determined for any y by using the numerical integration as defined in part 1. Write a program to determine the roots of this equation for each depth by using a root finding algorithm such as the bisection method. Again, you must use a general root finding function and apply it to this particular function. Do not use an analytic solution to solve this problem. Each function evaluation will have to be done using an integration algorithm such as the trapezoidal method.

Explanation / Answer

Problem:

To measure the volume of liquid in the tank, a depth gauge (measuring stick) can be used. It is inserted into an opening at the top and the level of liquid on the gauge can be used to determine the amount of liquid in the tank.

The tank has width w, height h and length len (in m). In the example output shown below, we take w=8, h=4 and len=7. Your programs should work for any values of w, h and len, not just these specific values.

We look at inserting a measuring stick that is already calibrated in units of 10 centimeters. This measuring gauge can be inserted into an opening at the top of the tank and used to measure the depth of the liquid in the tank.

Program coding:

// Function: y in terms of x

typedef double (*DFD) (double);
double f(double x)
{
    double A, B, W, H, y = 0.0;

    W = 8;
    H = 4;
    A = W / 2;
    B = H / 2;

    y = fabs(sqrt(pow(B, 2) * (1 - (pow(x, 2) / pow(A, 2)))));
    return y;
}

// Integrating the function -> Area
double trapezoidal_int(DFD f, double a, double b, int n)
{

    double x, dx, sum = 0.0;
    int i = 0;

    dx = (b - a) / n;
    sum = (f(a) + f(b)) / 2;
    for (i = 1, x = a + dx; i < n; i++, x += dx)
        sum += f(x);
    return sum * dx;
}

int main()
{
    double Volume, Len, Height, Width, Area, i, a, b = 0;

    a = 0;
    printf("Enter the width of the tank(in m): ");
    scanf("%lf", &Width);

     printf("Enter the heigth of the tank(in m): ");
    scanf("%lf", &Height);

    printf("Enter the length of the tank (in m): ");
    scanf("%lf", &Len);

    printf(" ");

    for (i = 0; i <= Height * 100; i = i + 10)
    {
        DFD my_func = &f;

        // Converting cm to m
        b = i / 100;
        Area = trapezoidal_int(my_func, a, b, 100);
        Volume = Area * Len;

        printf("Depth %.0lf cm: Volume %.6lf cubic metres", i, Volume);
        printf(" ");
    }
    return 0;
}

Output:

Depth 10 cm : Volume 1.188814 cubic meters

Depth 20 cm : Volume 3.336448 cubic meters

Depth 30 cm : Volume 5.992683 cubic meters . . .

Depth 380 cm : Volume 172.547399 cubic meters

Depth 390 cm : Volume 174.657114 cubic meters

Depth 400 cm : Volume 175.743037 cubic meters

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote