1.method:
Mat lab Code:
Given data:
A=4m^2, a=0.1m^2, g=9.81m/s^2, Q(t)=0.7e^-0.1t m^3/s and V(0)=10m^3
3. %%Matlab function for Question 3. function [tyl modifierEuler(ODEFUN,TSPAN,YO,N) tu TSPAN(1):1/N:TSPAN(2): % Euler steps y(1) YO; t(1) TSPANO1):h /N; for i-1:length(tn)-1 y(i+1)-y(i)+h(ODE FUN(t(i),y(i))); end end
Copyable code:
3.
%%Matlab function for Question 3.
function [t,y]=modifierEuler(ODEFUN,TSPAN,Y0,N)
tn=TSPAN(1):1/N:TSPAN(2);
% Euler steps
y(1)=Y0;
t(1)=TSPAN(1);h=1/N;
for i=1:length(tn)-1
t(i+1)= t(i)+h;
y(i+1)=y(i)+h*(ODEFUN(t(i),y(i)));
end
end
2.method:
%Matlab code for plotting ode45 and Euler method
clear all
clear all
%Constant terms
A=4;a=0.1;g=9.81;
v0 = 0;
tspan = [0 50];
%Quetion 2.
%code for solving using ode45
[t,v] = ode45(@vdt1, tspan, v0);
%Plotting the data using ode45
plot(t,v,'-o')
xlabel('t')
ylabel('v(t)')
title('t vs v(t) plot')
%Code for Euler solution
%all step size
N=[10 20 40 80];
h=1./N;
%Initial values
v0=0;
t0=0;
%t end values
tend=50;
fprintf('\n Due to nonlinear equation we cant solve it
analytically.\n')
for nn=1:length(N)
[t1,y1]=modifierEuler(@vdt1,tspan,v0,N(nn));
hold on
plot(t1,y1)
yy= spline(t,v,t1);
err_norm=norm(y1-yy);
fprintf('The error in Euler for N=%d is
%f\n',N(nn),err_norm)
end
legend('ode45','euler N=10','euler N=20','euler N=40','euler
N=80')
fprintf('\nBy increasing step length, error used to
decrease.\n')
Result
Due to nonlinear equation we cant solve it analytically.
The error in Euler for N=10 is 0.257780
The error in Euler for N=20 is 0.181609
The error in Euler for N=40 is 0.129477
The error in Euler for N=80 is 0.094032
By increasing step length, error used to decrease.
%Function for dvdt of modified Torcelli's law
function dvdt = vdt1(t,v)
A=4;a=0.1;g=9.81;
dvdt = 0.7*exp(-0.1*t)-a*sqrt((2*g*v)/A);
end
%%Matlab function for Question 2.
function [t,v]=tankVolume()
A=4;a=0.1;g=9.81;
v0 = 0;
tspan = [0 50];
%Quetion 2.
%solving using ode45
[t,v] = ode45(@(t,v)
0.7*exp(-0.1*t)-a*sqrt((2*g*v)/A), tspan, v0);
end
%%Matlab function for Question 3.
function [t,y]=modifierEuler(ODEFUN,TSPAN,Y0,N)
tn=TSPAN(1):1/N:TSPAN(2);
% Euler steps
y(1)=Y0;
t(1)=TSPAN(1);h=1/N;
for i=1:length(tn)-1
t(i+1)= t(i)+h;
y(i+1)=y(i)+h*(ODEFUN(t(i),y(i)));
end
end
3.method with graph:
In the last portfolio task, we modelled water draining from a tank with a small hole...
Part C (Based off week 9 workshop content) In the last portfolio task, we modelled water draining from a tank with a small hole in the bottom. To slow the volume decrease of the tank, a hose is placed in the top of tank with flow rate Q(t). This results in the following modified Torcelli's law NV Given A 4 m2, a 0.1 m2, g 9.81 m/s2, Qt).e0 m/s anod V(0) 10m3, -0.1t 1. Explain why this ODE cannot be...
The tank pictured in Figure 2 with height H and diameter D contains water, which drains through a small round hole with diameter d. Torricelli’s law states that the average velocity v of the draining water is , where g is the acceleration of gravity and h the water level. Derive an expression to describe the time taken for the tank to drain, if it is initially full of water. Future interplanetary astronauts could use the tank as a simple...
A large storage tank, open at the top and filled with water, develops a small hole in its side at a point 15.2 m below the water level. The rate of flow fron the leak is found to be 2.80 x 10-3 m3/min. (a) Determine the speed (in m/s) at which the water leaves the hole. m/s (b) Determine the diameter of the hole in mm). mm (c) What If? If the hole is 10.0 m above the ground and...
A large storage tank, open at the top and filled with water, develops a small hole in its side at a point 15.4 m below the water level. The rate of flow from the leak is found to be 3.00 x 10-3 m3/min. 1 (a) Determine the speed (in m/s) at which the water leaves the hole. 17.38 m/s (b) Determine the diameter of the hole (in mm). How is the flow rate related to the area of the hole...
A large storage tank, open at the top and filled with water, develops a small hole in its side at a point 16.2 m below the water level. The rate of flow from the leak is found to be 3.00 x 10-3 m3/min. 1 (a) Determine the speed (in m/s) at which the water leaves the hole. m/s (b) Determine the diameter of the hole (in mm). mm () What If? If the hole is 10.0 m above the ground...