Solving an Equation without solve command

1 view (last 30 days)
Hello Everyone,
I'm trying to solve the following equation for h
My problem is that the equation can't have an exact solution. However, there is a tolerance of 0.05. Therefore, I can't use the solve( command. I tried to obtain a solution but I couldn't. Do you guys have a suggestion?. Thank you in advance. This is my code;
load cal.mat
% Parameters
g = 9.81; % Gravity acceletration
% Inputs
Q = 40; % (m^3/sec)
So = 0.02 % slope of the channel
W = 4 % width of the channel
H = 3 % Depth of water
hin = H % depth of the water
hv = hin;% height of the canopy
% Obtain initial data
A = W*H % Cross-sectional Area of the Channel
P = W + hin + hin
R = A/P
% Setting Tolerance
Tol = 0.05 %meter
dif = 1
ht1 = hin + 0.01
ht = hin
for i=1:100
U = Q/A;
while dif > Tol
% for trees
ht = (((U)^2)*((g*((cal(i,2))^2)/(ht^(1/3))+0.5*((cal(i,1))*(cal(i,4))*ht*(cal(i,3))))))/(g*(1-0.25*(cal(i,4)*pi*((cal(i,3))^2))))
dif = ht1-ht
ht = ht + 0.01
end
end

Answers (1)

Luke Halberstadt
Luke Halberstadt on 17 Aug 2016
Why are you not permitted to find an exact solution? The equation you gave can be solved directly for h since if you look carefully, it is in the form h = a/h^(1/3) + b*h, which can be converted to h = (a/(1-b))^(3/4).

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!