A hollow cylindrical cylinder of radius r and length L is laying on its side. Th
ID: 3786203 • Letter: A
Question
A hollow cylindrical cylinder of radius r and length L is laying on its side. The cylinder is filled with liquid to a depth h. The volume V of liquid inside the cylinder can be calculated using the equation: V = [r^2 cos^-1(r - h/r) - (r - h) squareroot 2rh - h^2]L The inverse cosine can be calculated using either the built-in MATLAB function acos or the series expansion: cos^-1(x) = pi/2 - Sigma^infinity_n=0 (2n)!/(n!)^2 x^2n+1/4^n (2n + 1); |x| lessthanorequalto 1 Where the exclamation point refers to the factorial (factorial in MATLAB). For a cylinder of r = 1 m, L = 5 m filled with liquid to h = 1.9 m, write a function m-file that: accepts the inputs r, L and h calculates the percent error between the true value of V (using acos) and the approximation of V using the series expansion of the inverse cosine with 2, 5, 10 or 25 terms returns a vector containing the four percent error values (i.e., the percent error using 2, 5, 10 or 25 terms in the infinite series) Note that the value of n can be accessed in MATLAB by typing pi ().Explanation / Answer
Code:
function p=vol(r,l,h)
ratio=abs((r-h))/r;
V=((r^2)*acos(ratio)-((r-h)*sqrt((2*r*h-h^2))))*l; %Actual value using acos function
for i=0:1:2 %For two points
c2(i+1,1)=(pi/2)-((factorial(2*i)/factorial(i)^2)*ratio^(2*i+1))/((4^i)*(2*i+1));;
end
c2=sum(c2);
V2=((r^2)*c2-((r-h)*sqrt((2*r*h-h^2))))*l;
for i=0:1:5 %For five points
c5(i+1,1)=(pi/2)-((factorial(2*i)/factorial(i)^2)*ratio^(2*i+1))/((4^i)*(2*i+1));
end
c5=sum(c5);
V5=((r^2)*c5-((r-h)*sqrt((2*r*h-h^2))))*l;
for i=0:1:10 %For ten points
c10(i+1,1)=(pi/2)-((factorial(2*i)/factorial(i)^2)*ratio^(2*i+1))/((4^i)*(2*i+1));
end
c10=sum(c10);
V10=((r^2)*c10-((r-h)*sqrt((2*r*h-h^2))))*l;
for i=0:1:25 %For 25 points
c25(i+1,1)=(pi/2)-((factorial(2*i)/factorial(i)^2)*ratio^(2*i+1))/((4^i)*(2*i+1));
end
c25=sum(c25);
V25=((r^2)*c25-((r-h)*sqrt((2*r*h-h^2))))*l;
%Percent error
p(1,1)=((V-V2)/V)*100;
p(2,1)=((V-V5)/V)*100;
p(3,1)=((V-V10)/V)*100;
p(4,1)=((V-V25)/V)*100;
end
Output:
>> vol(1,5,1.9)
ans =
1.0e+03 *
-0.3789
-0.9329
-1.8629
-4.6565
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.