Answer the following question using MATLAB The question is: The velocity of water, 𝑣…
- User
Answer the following question using MATLAB The question is: 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?
Adjust the code that I provide so both the bisection and regula falsi methods work correctly. The velocity equation is adjusted just time so the intersection point is at v = 0. For example, in part a, the graph is shifted 4 down and the intersection point for the two lines in when v = 0. Ensure the new methods work
The code: function Lab2_Q1_t() %Part A: g = 9.81; L = 5; t = 3; v_targ = 0; v_v = 4;
%Evaluation of different H values to find v. H_values = linspace(0, 5, 1000); v_values = arrayfun(@(H) Velocity(H, g, L, t, v_v), H_values); %Creating graph of calculated values of velocity. figure plot(H_values, v_values); hold on plot(H_values, zeros(1, 1000), '-'); ylabel('Velocity [m/s]'); xlabel('Head [m]'); legend('v(H)', 'v(0)'); %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 = -2; H_b = 5; tol = 0.001; for i = 1:length(v_range) for j = 1:length(t_range) + 1 if j == 1 Bisection_result(i, j) = v_range(i); else [head, iter] = Bisection(v_range(i), t_range(j-1), g, L, H_a, H_b, tol); Bisection_result(i, j) = head; Bisection_iter(i,j-1) = iter; end end end disp('b) Head values (Bisection method)') disp([' Velocity', ' t = 1.0',' t = 1.5', ' t = 2.0', ' t = 2.5',' t = 3.0']); disp(Bisection_result) disp('b) Number of iterations (Bisection method)') disp(Bisection_iter) %Part C for i = 1:length(v_range) for j = 1:length(t_range) + 1 if j == 1 RegulaFalsi_result(i, j) = v_range(i); else [head, iter] = RegulaFalsi(v_range(i), t_range(j-1), g, L, H_a, H_b, tol); RegulaFalsi_result(i, j) = head; RegulaFalsi_iter(i,j-1) = iter; end end end disp('b) Head values (Regula Falsi method)') disp([' Velocity', ' t = 1.0',' t = 1.5', ' t = 2.0', ' t = 2.5',' t = 3.0']); disp(RegulaFalsi_result) disp('b) Number of iterations (Regula Falsi method)') disp(RegulaFalsi_iter)end
%Uses formula to calculate velocity. function v = Velocity(H, g, L, t, vel) v = sqrt(2H) * tanh( (sqrt(2H) / (2*L)) * t) - vel; end
- Assistant
- User
parts b and c do not work properly. They continue infinitely. in other words a solution is not calculated and therefore not shown. fix this
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.