Question: Please solve Problem 4 only. I also attached the prompts for Problems 2 and 3 for context. Problem 4 ( 2 5 points, CCOs #

Please solve Problem 4 only. I also attached the prompts for Problems 2 and 3 for context.
Problem 4(25 points, CCOs #1 & #8)
For the case described in problems 2 and 3, calculate the height of water in the tank at t =2500s to within 10^(-7) m using either the third-order Runge-Kutta method of Problem 1, or, for a 10 point deduction, the classical RK-4 method. Outside of your code, report the method you have chosen to solve this problem, the final step size \delta t employed and all supporting evidence that your result has the required accuracy. Note that for full credit it is not sufficient to only show that the estimated error is below the requested threshold, but you must also show that your chosen method converges as expected. Report h(t =2500s) as a floating point number in engineering notation with at least 10 mantissa digits.
Here are the functions to use:
function [x,y,k1,k2,k3,slope]= myRK3(f,xi,yi,h)
% Perform a single step of the 3rd-order Runge-Kutta method
% Inputs:
% f = Function handle representing d(y)/(d)x = f(x,y)
% xi = Current independent variable value (x_(i))
% yi = Current dependent variable value (y_(i))
% h = Step size
% Outputs:
% x = Updated independent variable value (x_(i+1))
% y = Updated dependent variable value (y_(i+1))
% Coefficients from the Butcher tableau
a1=0;
a2=(1)/(2);
a3=(3)/(4);
b21=(1)/(2);
b31=0;
b32=(3)/(4);
c1=(2)/(9);
c2=(1)/(3);
c3=(4)/(9);
% Compute k1, k2, k3
k1= f(xi,yi);
k2= f(xi + a2* h, yi + b21* h * k1);
k3= f(xi + a3* h, yi + b31* h * k1+ b32* h * k2);
% Compute the slope using the weights
slope = c1* k1+ c2* k2+ c3* k3;
% Update x and y values
x = xi + h;
y = yi + h * slope;
end
function rhs = myRHSE8(t,h)
% Calculate the right-hand-side of the ODE for water height in the tank
% Inputs:
% t = Current time (scalar)
% h = Current water height in the tank (scalar)
% Output:
% rhs = The right-hand-side of the ODE, representing d(h)/(d)t (scalar)
% Declare global variables
global g0 ag fg rho R r1 r2 h1 h2 c f1 f2;
% Calculate time-dependent acceleration g(t)
g_(t)= g0+ ag * cos(2* pi * fg * t);
% Calculate the inflow rate f(t)
f_(t)= c *(2+ sin(2* pi * f1* t + cos(2* pi * f2* t)));
% Calculate the outflow terms for visual simplicity
outflow1= r1^(2)* sqrt(max(0,h - h1));
outflow2= r2^(2)* sqrt(max(0,h - h2));
% Compute the RHS of the ODE
rhs =(f_(t)-(rho * pi * sqrt(2* g_(t)))*(outflow1+ outflow2))()/()(rho * pi * R^(2));
end
This is the script I used to solve Problem 3:
% Declare global variables
global g0 ag fg rho R r1 r2 h1 h2 c f1 f2;
% Define the given parameters
g0=9.81; %( m)/(s^(2))
ag =4; %( m)/(s^(2))
fg =0.0017; % Hz
rho =1000; % k(g)/(m^(3))
R =1.8; % m
r1=0.09; % m
r2=0.04; % m
h1=0.13; % m
h2=0.2; % m
c =31; % k(g)/(s)
f1=0.013; % Hz
f2=0.024; % Hz
% Initial conditions and simulation parameters
t0=0; % Initial time (s)
h0=0.35; % Initial height of water in the tank (m)
t_(f)inal =2500; % Final time (s)
dt =10; % Step size (s)
% Function handle for the ODE
f = @(t,h) myRHSE8(t,h);
% Initialize variables
t = t0; % Start time
h = h0; % Start height
% Time-stepping loop using 3rd-order Runge-Kutta
while t t_(f)inal
[t_(n)ext,h_(n)ext]= myRK3(f,t,h,dt); % RK3 step
t = t_(n)ext; % Update time
h = h_(n)ext; % Update height
end
% Store the result in the variable 'answer'
answer = h
Please solve Problem 4 only. I also attached the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!