Write a C program that outputs values of the volume of an elliptically shaped ta
ID: 3764917 • Letter: W
Question
Write a C program that outputs values of the volume of an elliptically shaped tank in a table.
(a) The values of the depth increment by 10 cm each time. Using the equation of an ellipse, find the volume at the specified depths by computing the cross-sectional area using numerical integration. The equation used must be a general one that would work for any function and not just this problem. Do you not use analytical methods.
(b)write a program that determines the depth corresponding to a given volume. The values of the volumes should correspond to multiples of 5 (5, 10, 15, 20, ...). To do so,you must find the equation of the root V(x)=depth. The function V(x) can be deteremined for any x by using numerical integratio . The program should determine the roots of an equation for every depth using a root finding alogorithm. This function must also work for the general function and use intgration algorithms.
Explanation / Answer
For Part A)
Given the equation of ellipse , say like this,
x^2/4 + y^2 =1;
Now in order to calculat ethe volume, we need to nnumerically integrate it like this
dV=(pi) * y^2 . dX
We know y^2= 1 - x^2/4. So,
dV=(pi) * (1 - x^2 /4) dX
Since the depth increases by 10 cm each time, so let the integral be defined from 0 to 10, and so on.
And let n be the number of subintervals, i.e. how many times do you need to sub-integrate it.
We will use Trapezoidal Rule for performing Integration.
int main()
{
float startInterval,endInterval,h,s;
int i,n;
printf("Enter startInterval, endInterval, no. of subintervals: ");
scanf("%f%f%d",&startInterval,&endInterval,&n);
h = (endInterval-startInterval)/n;
s = EllipseEquation(startInterval) + EllipseEquation(endInterval);
for(i = 1; i < n; i++){
s += 2*EllipseEquation(startInterval+i*h);
}
printf("Value of integral is %6.4f ",(h/2)*s);
// Once you get the Value of Intergal, that will be your volume :)
return 0;
}
float EllipseEquation(float x){
return 1/(1+x*x); // Specify your equation here.
}
For Part B)
Finding Roots of Equation for Every Depth.
To find roots, you will have to explicitly define the coeeficients of your equation. for ex, if your equation is 2x^2+ 4x+1=0. So here your coeeficients are 2, 4 and 1.
We will name them as a,b and c.
int main()
{
float a, b, c, determinant, r1,r2, real, imag;
determinant=b*b-4*a*c;
if (determinant>0)
{
r1= (-b+sqrt(determinant))/(2*a);
r2= (-b-sqrt(determinant))/(2*a);
printf("Roots are: %.2f and %.2f",r1 , r2);
}
else if (determinant==0)
{
r1 = r2 = -b/(2*a);
printf("Roots are: %.2f and %.2f", r1, r2);
}
else
{
real= -b/(2*a);
imag = sqrt(-determinant)/(2*a);
printf("Roots are: %.2f+%.2fi and %.2f-%.2fi", real, imag, real, imag);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.