To measure the volume of liquid in the elliptical tank, a depth gauge (measuring
ID: 3766496 • Letter: T
Question
To measure the volume of liquid in the elliptical 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 2 (60 marks)
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
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double W;
double H;
double L;
typedef double (*DFD) (double);
double f (double x11)
{
double a11 = H / 2.0;
double b11 = W / 2.0;
double y11 = (b11 / a11) * sqrt (a11 * a11 - x11 * x11);
return y11;
}
double trapezoidal (DFD f ,double a11, double b11, int no){
double x11, dx11, sum11=0.0;
int i=0;
dx11 = (b11-a11)/ no;
sum11 = (f(a11) + f(b11))/2;
for (i=1, x11 = a11 + dx11; i < no; i++, x11+= dx11)
sum11 += f(x11);
return 2.0 * sum11 * dx11;
}
int main ()
{
int height_cm;
printf ("Enter the Width of the tank (in m): ");
scanf ("%lf",&W);
printf ("Enter the Height of the tank (in m): ");
scanf ("%lf",&H);
printf ("Enter the Length of the tank(in m): ");
scanf ("%lf",&L);
for (height_cm = 0; height_cm <= H * 100; height_cm += 10) {
double h = height_cm / 100.0;
double area11 = trapezoidal (&f, H / 2 - h, H / 2, 100);
double volume = area11 * L;
printf ("Volume %.6lf cubic metres:Depth %d cm ",
volume,height_cm);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.