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 only. I also attached the prompts for Problems and for context.
Problem points, CCOs # & #
For the case described in problems and calculate the height of water in the tank at t s to within m using either the thirdorder RungeKutta method of Problem or for a point deduction, the classical RK 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 ht s as a floating point number in engineering notation with at least mantissa digits.
Here are the functions to use:
function xykkkslope myRKfxiyih
Perform a single step of the rdorder RungeKutta method
Inputs:
f Function handle representing dydx fxy
xi Current independent variable value xi
yi Current dependent variable value yi
h Step size
Outputs:
x Updated independent variable value xi
y Updated dependent variable value yi
Coefficients from the Butcher tableau
a;
a;
a;
b;
b;
b;
c;
c;
c;
Compute k k k
k fxiyi;
k fxi a h yi b h k;
k fxi a h yi b h k b h k;
Compute the slope using the weights
slope c k c k c k;
Update x and y values
x xi h;
y yi h slope;
end
function rhs myRHSEth
Calculate the righthandside 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 righthandside of the ODE, representing dhdt scalar
Declare global variables
global g ag fg rho R r r h h c f f;
Calculate timedependent acceleration gt
gt g ag cos pi fg t;
Calculate the inflow rate ft
ft c sin pi f t cos pi f t;
Calculate the outflow terms for visual simplicity
outflow r sqrtmaxh h;
outflow r sqrtmaxh h;
Compute the RHS of the ODE
rhs ftrho pi sqrt gtoutflow outflowrho pi R;
end
This is the script I used to solve Problem :
Declare global variables
global g ag fg rho R r r h h c f f;
Define the given parameters
g; ms
ag ; ms
fg ; Hz
rho ; kgm
R ; m
r; m
r; m
h; m
h; m
c ; kgs
f; Hz
f; Hz
Initial conditions and simulation parameters
t; Initial time s
h; Initial height of water in the tank m
tfinal ; Final time s
dt ; Step size s
Function handle for the ODE
f @th myRHSEth;
Initialize variables
t t; Start time
h h; Start height
Timestepping loop using rdorder RungeKutta
while t tfinal
tnexthnext myRKfthdt; RK step
t tnext; Update time
h hnext; Update height
end
Store the result in the variable 'answer'
answer h
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
