You are on page 1of 8

9/11/2016

MATLABCentralOPENCHANNELFLOWprofiles

OPENCHANNELFLOWprofiles
Subject:OPENCHANNELFLOWprofiles
From:PiYaL
Date:15Nov,200905:19:06
Message:1of2
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam
Ineedamatlabscriptsdevelopedfor>>>improvedeulermethod,
standardstepmethodandfourthorderRungekuttamethodand
simultaneoussolutionmethod.
USINGEACHMETHOD>M1,M2,andS3profileshastobeplotted.Plots
shouldcontainbedelevation,normaldepth,criticaldepthlines.in
caseofM1profile,setthedownstreamdepthas2*Ynandincaseof
M2profilethedownstreamdepth1.05*YcandincaseofS3profile
Upstreamdepthas0.05m.
Thebelowsamplescriptdoneformodifiedeulermethod>>
Thanksinadvance.

%CalculatingtheNormalandCriticalDepthforDifferentOpenChannel
%CrossSections.
%ParametersforTrapezoidal,Rectangular,andTriangularCross
Section
clearall
Q=100%Discharge(m^3/s)
s=0.00025%Bottomslope
n=0.040%ManningRoughnessCoefficient
yinitial=0.1%InitialGuesstostarttheiterations
%%NormalandCriticalDepthsCalculation
%LoopforNormalDepth
forj=1:3
b=[10500]%BottomWidth(m)forTrap,Rect,Tria.x
sec.respectively.
z=[1.00.01.0]%SideSlopeforTrapezoidal,
Rectangular,andTriangularXsecrespectively.
y(1)=yinitial
i=1
dy(1)=1e1
while(abs(dy(i))>1e3)
https://au.mathworks.com/matlabcentral/newsreader/view_thread/265885

1/8

9/11/2016

MATLABCentralOPENCHANNELFLOWprofiles

A(i)=b(j)*y(i)+z(j)*(y(i))^2
P(i)=b(j)+2*(z(j)^2+1)^(0.50)*y(i)
R(i)=A(i)/(P(i))
f(i)=sqrt(s)/n*(A(i)*R(i)^(2/3))Q%function
ff(i)=sqrt(s)/n*((4/3)*R(i)^(5/3)*sqrt(1+z(j)^2)+5/3*R(i)^
(2/3)*(b(j)+2*z(j)*y(i)))%f'Derivative
y(i+1)=y(i)f(i)/ff(i)
dy(i+1)=f(i)/ff(i)
i=i+1
end
normaldepth(j)=y(i)
conv(j)=i
end

forj=1:3%SideSlopeforTrapezoidal,Rectangular,and
TriangularXsecrespectively.
%LoopforCriticalDepth
alpha=1
theta=0
yc(1)=yinitial
ic=1
dyc(1)=1e1
while(abs(dyc(ic))>1e3)
Ac(ic)=b(j)*yc(ic)+z(j)*(yc(ic))^2
Bc(ic)=b(j)+2*z(j)*yc(ic)
Pc(ic)=b(j)+2*(z(j)^2+1)^(0.50)*yc(ic)
Rc(ic)=Ac(ic)/(Pc(ic))
Dc(ic)=Ac(ic)/(b(j)+2*z(j)*yc(ic))
fc(ic)=Ac(ic)^(3/2)*Bc(ic)^(1/2)Q/sqrt(9.81/alpha)%
function
ffc(ic)=Ac(ic)^(3/2)*(1/2)*Bc(ic)^(3/2)*2*z(j)+Bc(ic)^(1/2)*
(3/2)*Ac(ic)^(1/2)*Bc(ic)%f'Derivative
yc(ic+1)=yc(ic)fc(ic)/ffc(ic)
dyc(ic+1)=fc(ic)/ffc(ic)
ic=ic+1
end
criticaldepth(j)=yc(ic)
convc(j)=ic
end
%%WaterSurfaceCalculations
dx=2.0%Intervalinchanneldirection
Y=2.0*normaldepth(1)%InitialWaterDepthatthecontrollocation
%Y=1.05*criticaldepth(1)
%Y=0.05
Dir='U'%directionofsolution:Upstream(U)or
https://au.mathworks.com/matlabcentral/newsreader/view_thread/265885

2/8

9/11/2016

MATLABCentralOPENCHANNELFLOWprofiles

Downstream(D)?','s')
ifDir=='U'
dx=dx
end
L=40000%totallengthofthechannel
Nx=round(abs(L/dx))
BedElev(1)=0%BeginingofBedElevation
WaterElev(1)=Y(1)%BeginingofWaterElevation
b=b(1)%channelbottomwidthforTrap.
Section
z=z(1)%SideSlopeforTrap.Section
fori=1:Nx
A(i)=b*Y(i)+z*Y(i)^2%Aream^2
B(i)=b+2*z*Y(i)%TopWidth
P(i)=b+2*Y(i)*sqrt(1+z^2)%WettedPerimeter
R(i)=A(i)/P(i)%Hydr.radius
V(i)=Q/A(i)%Velocity
Sf(i)=n^2*V(i)^2/(R(i)^(4/3))%Energyslope
f(i)=(sSf(i))/(1Q^2*B(i)/9.81/A(i)^3)%dy/dx=f=(ssf/(1fr^2))
yy(i)=Y(i)+0.5*f(i)*dx%firstmodifieddepthor
y(i+1/2)=yold+.5*dx*f'
A(i)=b*yy(i)+z*yy(i)^2%Calculatenewareabut
usingyywhichisymod1
B(i)=b+2*z*yy(i)%Calculatenewtopwidth
butusingyywhichisymod1
P(i)=b+2*yy(i)*sqrt(1+z^2)%Calculatenewwetted
perimeterbutusingyywhichisymod1
R(i)=A(i)/P(i)
V(i)=Q/A(i)
Sf(i)=n^2*V(i)^2/(R(i)^(4/3))
ff(i)=(sSf(i))/(1Q^2*B(i)/9.81/A(i)^3)%Calculatenewdy/dxbut
usingyywhichisymod1
Y(i+1)=Y(i)+ff(i)*dx%Calcualtefinaly
whichisyold+f'(y(i+1/2))*dx
BedElev(i+1)=dx*(i)*s%Bedelevation
forplottingpurpose
WaterElev(i+1)=BedElev(i+1)+Y(i+1)%Water
surfaceelevationforplottingpurpose
X(i+1)=dx*i%X:distancealong
thechannelin(m)
end
CriticalElev=BedElev.*1.0+criticaldepth(1)%getthecriticaldepth
lineforplottingpurpose
NormalElev=BedElev.*1.0+normaldepth(1)%getthenormaldepth
lineforplottingpurpose
Yfinalm=Y(i+1)
figure(1)
plot(X,BedElev,'k','LineWidth',2)hold
plot(X,WaterElev,'LineWidth',2)
https://au.mathworks.com/matlabcentral/newsreader/view_thread/265885

3/8

9/11/2016

MATLABCentralOPENCHANNELFLOWprofiles

plot(X,CriticalElev,'.r')
plot(X,NormalElev,'m')
h=legend('Bed','WaterSurface','CriticalDepthLine','NormalDepth
Line',1)
xlabel('Length(m)')
ylabel('Elevation(m)')
title('WaterSurfaceProfile')
XY=[X'BedElev'WaterElev']
d={'X','BedElev','WaterElev'}
dir=pwd
xlswrite('waterdepth.xlsx',d,'WaterSurface','A1')
xlswrite('waterdepth.xlsx',XY,'WaterSurface','A2')

Subject:OPENCHANNELFLOWprofiles
From:TideMan
Date:15Nov,200910:14:44
Message:2of2
Replytothismessage
AddauthortoMyWatchList
Vieworiginalformat
Flagasspam
OnNov15,6:19pm,PiYaL<yasha...@yahoo.com>wrote:
>Ineedamatlabscriptsdevelopedfor>>>improvedeulermethod,
>standardstepmethodandfourthorderRungekuttamethodand
>simultaneoussolutionmethod.
>USINGEACHMETHOD>M1,M2,andS3profileshastobeplotted.Plots
>shouldcontainbedelevation,normaldepth,criticaldepthlines.in
>caseofM1profile,setthedownstreamdepthas2*Ynandincaseof
>M2profilethedownstreamdepth1.05*YcandincaseofS3profile
>Upstreamdepthas0.05m.
>
>Thebelowsamplescriptdoneformodifiedeulermethod>>
>Thanksinadvance.
>
>%CalculatingtheNormalandCriticalDepthforDifferentOpenChannel
>%CrossSections.
>
>%ParametersforTrapezoidal,Rectangular,andTriangularCross
>Section
>clearall
>Q=100%Discharge(m^3/s)
>s=0.00025%Bottomslope
>n=0.040%ManningRoughnessCoefficient
>yinitial=0.1%InitialGuesstostarttheiterations
>%%NormalandCriticalDepthsCalculation
https://au.mathworks.com/matlabcentral/newsreader/view_thread/265885

4/8

9/11/2016

MATLABCentralOPENCHANNELFLOWprofiles

>
>%LoopforNormalDepth
>
>forj=1:3
>b=[10500]%BottomWidth(m)forTrap,Rect,Tria.x
>sec.respectively.
>z=[1.00.01.0]%SideSlopeforTrapezoidal,
>Rectangular,andTriangularXsecrespectively.
>y(1)=yinitial
>i=1
>dy(1)=1e1
>while(abs(dy(i))>1e3)
>A(i)=b(j)*y(i)+z(j)*(y(i))^2
>P(i)=b(j)+2*(z(j)^2+1)^(0.50)*y(i)
>R(i)=A(i)/(P(i))
>f(i)=sqrt(s)/n*(A(i)*R(i)^(2/3))Q%function
>ff(i)=sqrt(s)/n*((4/3)*R(i)^(5/3)*sqrt(1+z(j)^2)+5/3*R(i)^
>(2/3)*(b(j)+2*z(j)*y(i)))%f'Derivative
>y(i+1)=y(i)f(i)/ff(i)
>dy(i+1)=f(i)/ff(i)
>i=i+1
>end
>normaldepth(j)=y(i)
>conv(j)=i
>
>end
>
>forj=1:3%SideSlopeforTrapezoidal,Rectangular,and
>TriangularXsecrespectively.
>%LoopforCriticalDepth
>alpha=1
>theta=0
>yc(1)=yinitial
>ic=1
>dyc(1)=1e1
>while(abs(dyc(ic))>1e3)
>
>Ac(ic)=b(j)*yc(ic)+z(j)*(yc(ic))^2
>Bc(ic)=b(j)+2*z(j)*yc(ic)
>Pc(ic)=b(j)+2*(z(j)^2+1)^(0.50)*yc(ic)
>Rc(ic)=Ac(ic)/(Pc(ic))
>Dc(ic)=Ac(ic)/(b(j)+2*z(j)*yc(ic))
>fc(ic)=Ac(ic)^(3/2)*Bc(ic)^(1/2)Q/sqrt(9.81/alpha)%
>function
>ffc(ic)=Ac(ic)^(3/2)*(1/2)*Bc(ic)^(3/2)*2*z(j)+Bc(ic)^(1/2)*
>(3/2)*Ac(ic)^(1/2)*Bc(ic)%f'Derivative
>yc(ic+1)=yc(ic)fc(ic)/ffc(ic)
>dyc(ic+1)=fc(ic)/ffc(ic)
>ic=ic+1
https://au.mathworks.com/matlabcentral/newsreader/view_thread/265885

5/8

9/11/2016

MATLABCentralOPENCHANNELFLOWprofiles

>end
>criticaldepth(j)=yc(ic)
>convc(j)=ic
>end
>%%WaterSurfaceCalculations
>
>dx=2.0%Intervalinchanneldirection
>Y=2.0*normaldepth(1)%InitialWaterDepthatthecontrollocation
>%Y=1.05*criticaldepth(1)
>%Y=0.05
>Dir='U'%directionofsolution:Upstream(U)or
>Downstream(D)?','s')
>ifDir=='U'
>dx=dx
>end
>L=40000%totallengthofthechannel
>Nx=round(abs(L/dx))
>BedElev(1)=0%BeginingofBedElevation
>WaterElev(1)=Y(1)%BeginingofWaterElevation
>b=b(1)%channelbottomwidthforTrap.
>Section
>z=z(1)%SideSlopeforTrap.Section
>fori=1:Nx
>A(i)=b*Y(i)+z*Y(i)^2%Aream^2
>B(i)=b+2*z*Y(i)%TopWidth
>P(i)=b+2*Y(i)*sqrt(1+z^2)%WettedPerimeter
>R(i)=A(i)/P(i)%Hydr.radius
>V(i)=Q/A(i)%Velocity
>Sf(i)=n^2*V(i)^2/(R(i)^(4/3))%Energyslope
>f(i)=(sSf(i))/(1Q^2*B(i)/9.81/A(i)^3)%dy/dx=f=(ssf/(1fr^2))
>yy(i)=Y(i)+0.5*f(i)*dx%firstmodifieddepthor
>y(i+1/2)=yold+.5*dx*f'
>A(i)=b*yy(i)+z*yy(i)^2%Calculatenewareabut
>usingyywhichisymod1
>B(i)=b+2*z*yy(i)%Calculatenewtopwidth
>butusingyywhichisymod1
>P(i)=b+2*yy(i)*sqrt(1+z^2)%Calculatenewwetted
>perimeterbutusingyywhichisymod1
>R(i)=A(i)/P(i)
>V(i)=Q/A(i)
>Sf(i)=n^2*V(i)^2/(R(i)^(4/3))
>ff(i)=(sSf(i))/(1Q^2*B(i)/9.81/A(i)^3)%Calculatenewdy/dxbut
>usingyywhichisymod1
>Y(i+1)=Y(i)+ff(i)*dx%Calcualtefinaly
>whichisyold+f'(y(i+1/2))*dx
>BedElev(i+1)=dx*(i)*s%Bedelevation
>forplottingpurpose
>WaterElev(i+1)=BedElev(i+1)+Y(i+1)%Water
>surfaceelevationforplottingpurpose
https://au.mathworks.com/matlabcentral/newsreader/view_thread/265885

6/8

9/11/2016

MATLABCentralOPENCHANNELFLOWprofiles

>X(i+1)=dx*i%X:distancealong
>thechannelin(m)
>end
>CriticalElev=BedElev.*1.0+criticaldepth(1)%getthecriticaldepth
>lineforplottingpurpose
>NormalElev=BedElev.*1.0+normaldepth(1)%getthenormaldepth
>lineforplottingpurpose
>Yfinalm=Y(i+1)

>figure(1)
>plot(X,BedElev,'k','LineWidth',2)hold
>plot(X,WaterElev,'LineWidth',2)
>plot(X,CriticalElev,'.r')
>plot(X,NormalElev,'m')
>h=legend('Bed','WaterSurface','CriticalDepthLine','NormalDepth
>Line',1)
>xlabel('Length(m)')
>ylabel('Elevation(m)')
>title('WaterSurfaceProfile')
>XY=[X'BedElev'WaterElev']
>d={'X','BedElev','WaterElev'}
>dir=pwd
>xlswrite('waterdepth.xlsx',d,'WaterSurface','A1')
>xlswrite('waterdepth.xlsx',XY,'WaterSurface','A2')

MATLABNewsgroup

IrecommendthatyougetaholdofHenderson'stextbook"OpenChannel
Flow".It'sveryold(1966),butithasallyouneedtodothis
homeworkassignment.
Atleast,Ifounditdid,backin1968whenIhadthesameassignment
asyouhave.Butwedidn'thaveMatlabbackthen.OnlyFortran,
usingHollerithcardsonanIBMmainframe.

FeedforthisThread
AddtoMyWatchList
WhatisaWatchList?

TagsforthisThread
Notagsareassociatedwiththisthread.

Whataretags?
Atagislikeakeywordorcategorylabelassociatedwitheachthread.Tagsmakeiteasierforyoutofindthreadsof
interest.
Anyonecantagathread.Tagsarepublicandvisibletoeveryone.

https://au.mathworks.com/matlabcentral/newsreader/view_thread/265885

7/8

9/11/2016

MATLABCentralOPENCHANNELFLOWprofiles

19942016TheMathWorks,Inc.

MATLABNewsgroup

https://au.mathworks.com/matlabcentral/newsreader/view_thread/265885

8/8

You might also like