consider the following question: The velocity of water, 𝑣 (m/s), discharged from a…
- User
consider the following question: The velocity of water, 𝑣 (m/s), discharged from a cylindrical tank through a long pipe can be computed as 𝑣 = √2𝑔𝐻 tanh (√2𝑔𝐻 2𝐿 𝑡) where 𝑔 = 9.81 m/s2, 𝐻 = initial head (m), 𝐿 = pipe length (m), and 𝑡 = elapsed time (s). a. Graphically determine the head needed to achieve 𝑣 = 4 m/s, in 3 s for 5 m-long pipe. b. Determine the head for 𝑣 = 3 − 6 m/s (at 0.5 m/s increments) and times of 1 to 3 s (at 0.5 s increments) via the bisection method with stopping criteria of 0.1% estimated relative error. c. Perform the same series of solutions with the regula falsi method where you choose the same starting points and convergence tolerance. d. Which numerical method converged faster?
adding to the following code answer part b. For this part, the bisection function must calculate 2 things. First it must keep calculating the head value until it is in tolerance. Second it must keep try of the number of iterations that it took to get the final answer. The output of the bisection function should be a 1 x 2 matrix that contains both the head value and the number of iterations. This will then be separated into different matrices.
add to the matlab code: function Lab2_Q2() %Part A: g = 9.81; L = 5; t = 3; v_targ = 4;
code%Evaluation of different H values to find v. H_values = linspace(0, 20, 1000); v_values = arrayfun(@(H) Velocity(H, g, L, t), H_values); %Creating graph of calculated values of velocity. figure plot(H_values, v_values); hold on plot(H_values, v_targ * ones(1, 1000), '-'); ylabel('Velocity [m/s]'); xlabel('Head [m]'); legend('v(H)', 'v(4)'); %Finding closest H value to target velocity (4 m/s). diff = abs(v_targ - v_values); min_diff = min(diff); min_diff_idx = find(diff == min_diff,1, 'first'); H_graphical = H_values(min_diff_idx); disp(['a) ', num2str(H_graphical) , ' m']) %Part B: v_range = 3:0.5:6; t_range = 1:0.5:3; %Assigning initial values. H_a = 0; H_b = 20; tol = 0.001; %fix tolerance for i = 1:length(v_range) + 1 for j = 1:length(t_range) if j == 1 Bisection_result (i, j) = v_range(i); else Bisection_result (i, j) = Bisection(v_range(i), t_range(j), g, L, H_a, H_b, tol); end end end - Assistant
You can modify the code as follows to complete part b:
matlab - User
adjust the code so instead of using a tolerance the estimated relative error is used. The estimated relative error must be less than or equal to 0.1%. X^n is the estimated numerical solution in the last iteration and V^(n-1) is the estimated numerical solution in the preceding iteration
The formula for estimated relative error is: abs((X^n - X^(n-1))/(X^(n-1)))
- Assistant