MATLAB Files (PDF)
MATLAB Files (PDF)
MATLAB Files (PDF)
%============START=============%
%initial conditions
t0 = 0 ; y0 = 6.5 ;
for i = 1:N
t = T(i) + delx;
y = fsolve ( @(y) y - Y(i) - delx*( f(y, t) ) , Y(i) ) ; %Euler's imlicit backward formula
end
%============END=============%
%====INTERPOLATION of 2nd-Order POLYNOMIAL (using Newton's
Interpolation Method)=======
%[MATLAB filename: Interpolation.m]
% 1) First I constructed Quadratic Polynomial using 3 data points (x-y coordinates) from
% Euler Implicit Method or from ODE45 plots of given ODE. Although, both methods...
% produce almost plots but in our case, Euler Implicit Method is more accurate).
%
% 2) Then using this Polynomial’s graph, I selected 3 points on the graph to find Inverse
% Interpolating Polynomial.
%
% 3) Then used this to calculate root which is the REQUIRED TIME t
%To select proper data points, I chose Data Cursor in the Figure Toolbar from figure
window.
%==============START=================%
clear, clc ;
%Selected data points from the graph of Interpolted Polynomial (Figure 3 )
x0 = 250 ;
y0 = 0.333 ;
f0 =y0 ; %b0
t = T(k) + delx;
T(k+1) = t ;
end
figure(2);
plot(T, Y, 'LineWidth', 1.5);
title(' interpolated Polynomial graph t versus h)');
xlabel(' Time (t) (seconds) ');
ylabel(' Water Level (h) in tank (meters) ');
grid on
%==============END=================%
%=======REVERSE INTERPOLATION========
% Root finding of the Polynomial %
%===============START=================
%[Matlab filename: reverse_interpolation.m ]
clear, clc ;
%Selected data points from the graph of Interpolted Polynomial (Figure 5 )
y0 = 0.1297 ;
x0 = 255.5 ;
y = [0.3772 0.6886] ; % y1 and y2
x = [248.8 239.3] ; % x1 and x2
f0 =y0 ; %b0
%Now using fzero solver, it'll give the root which will be required time,
%==============END================
%========================================%
%===============START===================%
clear; clc
%given time (in seconds) at which h is to be found.
t = 60;
fun = (@(h) 2.65767*t + 80*h.^(3/2) - 6*h.^(5/2) - 679.44435 ) ; %eq. (3) derived from given
ODE
[x ,fval ] = fzero(fun,intervalX,options) ;
for i=1:N
%r as a function of tank radius for desired flow rate obtained using
%t0 and tf and related hi and hf
r = sqrt ( (5*(2-4*sqrt(2))*(R(i))^(5/2) - 3*(2-8*sqrt(2) )*(R(i))^(5/2) ) /(t*100*66.4417) ) ;
rmatrix(i) = real(r) ;
end
%============END===========%
%===========PART C====================%
%============START===========%
clc ; clear ;
t = 120.0 ;
N = 100 ;
R=3; %R = [3 5] given.
Rend = 5 ;
delx = (Rend - R)/N ;
R = linspace(3, 5, N);
rmatrix = zeros(1, N) ;
for i=1:N
%r as a function of tank radius for desired flow rate obtained using
%t0 and tf and related hi and hf
r = sqrt ( (5*(2-4*sqrt(2))*(R(i))^(5/2) - 3*(2-8*sqrt(2) )*(R(i))^(5/2) ) /(t*100*66.4417) ) ;
rmatrix(i) = real(r) ;
end
%============END===========%
%============START==============%
%initial conditions
t0 = 0 ; y0 = 6.5 ;
for i = 1:N
t = T(i) + delx;
y = fsolve ( @(y) y - Y(i) - delx*( f(y, t) ) , Y(i) ) ; %Euler's imlicit backward formula
T(i+1) = t ;
if t == 60.0
Req_h = y ;
Time_t = t;
plot(t, y, 'or', 'MarkerSize', 6, 'LineWidth', 2); %mark red
point on the graph
end
Y(i+1) = y ;
end
hold on;
plot(T, Y, 'LineWidth',1.5); %plot t and h