Write a MATLAB script to visually demonstrate Torricelli’s law. Generate a plot
ID: 3591535 • Letter: W
Question
Write a MATLAB script to visually demonstrate Torricelli’s law. Generate a plot of Flow velocity (m/s) as a function of the height (m) of the liquid above the opening from the time the opening is created until the height reaches the level of the opening, in 0.1 meter increments. The algorithm should input the diameter of the cylindrical tank (in meters) and the volume of liquid (cubic meters) that is to be placed in the tank. Place appropriate labels on the axes of the graph; add a descriptive title. For these calculations, the opening is on the side of the tank at the bottom. Assume that the actual height of the opening is negligible and the size of the opening creates no restrictions in fluid velocity. Include a sketch of your graph
Explanation / Answer
function solveDifferentialEquation
%This function solves y'+y = x from starttime to endtime with y(0) = intialCondition
%Parameter initializations
starttime = 0;
endtime = 20;
initialCondition = -2;
function yprime = DifferentialEquationFunction(x,y)
yprime = y - x;
end
[xVals,yVals] = ode45(@DifferentialEquationFunction,[starttime,endtime],initialCondition);
plot(xVals,yVals);
end %Function Complete
function solveDifferentialEquation2
% Function to solve the differential equation
% of a particle in motion due to impact of an external sinusoidal
% force ( yprime = F*sin(w*t) - C*y )
% from a starttime to stoptime, where the intial y value is assigned as
% initialCondition
%Parameter initializations
n = 5;
1.45, 1.34, 1.81, 3.5]; %acts as a scalar vector that scales the parameters by its %entries.
C = 10.*onesv;
F = 1.*onesv;
w = 1.*onesv; %With scaled frequencies,w, the plots should show a trend of increasing spread with t5he 3rd plot as an exception since 1.34 defies the pattern.
starttime = 0;
endtime = 20;
initialCondition = 0;
counter = 1;
%Loop to solve the ODE and plot five different graphs.
for indeX = 1:n
[t,y] = ode45(@DifferentialEquationFunction2,[starttime,endtime],initialCondition);
counter = counter + 1;
figure(indeX)
plot(t,y);
title('Solution to differential equation')
xlabel('time')
ylabel('y-value')
end
function yprime = DifferentialEquationFunction2(t,y) % Function defining the ODE
yprime = F(counter)*sin(w(counter)*t) - C(counter)*y;
end
end %Function Complete
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.