Question

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 Torcellis law: dV Given A 4 m2, a -0.1 m2, g 9.81 m/s2, Q(t) 0.7e-0.11 m3/s and V(0) 10 m3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

Gol START coDE Sol:- 1 % felavant constants [e,Ye odeys@lb,V) e-a*Sygb(2g¥ yla), o 501 Vo) ; %uSing ode 45 to solve the Pa end END CODE using the follow code, ue cxeate a Pot of the solution cunve be lou: >> Plotle,V)% plot the Solution 10 4.499 4498 4.497 4396 4.995 9.994 :413 9:-492 6 5 1o 15 0 8.5 30 35 40 45 56

Add a comment
Know the answer?
Add Answer to:
In the last portfolio task, we modelled water draining from a tank with a small hole...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT