
%  manningx.m    by w. huang 10/13/1999
%' This file shows how to convert general variable into constant in an eqation f(x).'
%' Then, you can use the fzero function to find the root.'
%' enter to continue'
%pause
% Manning equation: Q= (A^(5/3)/P^0.6667)*S^0.5/n
% 
% for the example given in page 161;
% b=50, n= 0.04, s= 0.002, Q= 600;


% 1) read or define the constant in the Manning equation 
%' These constant numbers are converted into string'

%pause
' Find normal depth for rectangular channel '

b= input('channel width =?')
n= input ('Manning Coef=?')
s= input ('bottom slope =?')
Q = input (' flowrate =?')
%b=50
%n=0.04
%s=0.002
%Q=600

% 2) convert above constrant to strings
sb = num2str(b);
sn = num2str(n);
ss = num2str (s);
sQ = num2str (Q);

' pause, press enter to continue'
% pause

% 3) make a function by using above constants (in string format now)

temp1 = ['(' sb '*x)^(5/3)']
temp2 = ['(' sb '+2*x)^(2/3)']
temp3 = [ss '^0.5']

f=['1/' sn '*' temp1 '/' temp2 '*' temp3 '-' sQ]

%
' Here is the function from the Manning equation '
%
% 4)to find the normal depth, press enter 
' to find the normal depth, press enter '

pause

ndepth = fzero(f,4)

'critical depth='

yc= ((Q/b)^2/9.8)^(1/3)


%



%  you can also try the following simple test :
% f=['1' ' + x^(3/2)']; 
% fzero(f,1)  
% its works

