Use Matlab A spherical water tank is elevated to a height H. The diameter of the
ID: 3882898 • Letter: U
Question
Use Matlab
A spherical water tank is elevated to a height H. The diameter of the tank is D_ The water supply pipe from the tank is connected to the bottom of the tank and runs directly to the ground. The diameter of the supply pipe is D_ Write a user written function that expects (as the argument) scalar values for the two diameters, the tank height, and the water level (from the ground). The function must return the volume of water contained in the tank and supply pipe combined. The syntax of your function should be: TV (Dtank, Dpipe, Htank, Hwater) Test your code on for a tank diameter of 5 meters, a pipe diameter of 0.5 meters, a tank height of 50 meters, and a water height of 51 meters. In the command window type a = TV(5, 0.5, 50, 51). Check the result.Explanation / Answer
Matlab code:
Create a file named TV.m and pasted given code into it! Filename must be TV.m
TV.m
function [V] = TV(Dtank,Dpipe,Htank,Hwater)
% Total volume = volume of pipe + water volume in tank
h = Htank - Dtank/2; %height of pipe
r = Dpipe/2;
pipe_v = pi*r^2*h; %volume if cylinder = *r^2*h
ht = Hwater - h; %water height in sphere
rt = Dtank/2;%radius of tank
water_in_tank = pi*(ht^2)*rt - (pi/3)*(ht^3);
V = pipe_v + water_in_tank;
end
Sample Test:
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.