%Trapezoid.m   by A.Mills 10/19/99
%'This file shows how to convert a general variable into a constant in an equation f(x).'
%'Then, you can use the fzero function to find the root.'
%'Enter to continue.'
%pause
%Critical depth equation: 1=(h*(Q^2)*B)/(g*A^3)
%
%for the example given on page 161 and for homework;
%b=40, Q=600, a=4, h=1, g=9.81;


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

%pause
'Find critical depth for trapezoidal channel'

b=input('channel width=?');
Q=input('flowrate=?');
a=input('side slope=?');
g=input('gravity=?');
%b=40
%Q=600
%a=4
%h=1
%g=9.81

%2)convert above constants to strings
sb = num2str(b);
sQ = num2str(Q);
sa = num2str(a);
sg = num2str(g);

'pause, press enter to continue'
%pause

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

temp4 = ['(' sb '+ 2 *' sa '* x) *' sQ '^2 ']
temp5 = ['(' sb '* x +' sa '* x^2)^3 *' sg]

f=[temp4 '/ (' temp5 ') - 1']

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

pause

ndepth = fzero(f,4)


%






























