Answered step by step
Verified Expert Solution
Question
1 Approved Answer
make a matlab code that:Calculates flow depth and velocity for supply Q 1 other codes that may help:function data = readData ( filename ) fid
make a matlab code that:Calculates flow depth and velocity for supply Q
other codes that may help:function data readDatafilename
fid fopenfilenamer;
if fid
errorError opening file filename;
end
data struct;
while ~feoffid
line fgetlfid;
if isemptyline
continue;
end
Split the line into parameter and value
parameter value strtokline:;
Remove the colon and whitespace from the value
value strtrimstrrepvalue:;
Remove comments lines starting with #
value strtokvalue#;
Convert the value to a number if it is not empty
if ~isemptyvalue
numValue strdoublevalue;
Check if the conversion was successful
if ~isnannumValue
data.strtrimparameter numValue;
else
warningCould not convert value for parameter parameter to a number.;
end
else
warningEmpty value for parameter parameter ;
end
end
fclosefid;
end
filename inputEnter file name: s;
Read data from the specified file
data readDatafilename;
Extract values from the structure
d data.DIAMETER;
h data.DEPTH;
Call the horseshoeFlow function with the obtained values
P A horseshoeFlowd h;
Display results or perform additional operations
fprintfWetted Perimeter P: f
P;
fprintfCrosssectional Area A: f
A;
function P A horseshoeFlowd h
Constants
Calculate h
hd;
if h && h h
Case : h h
A h dh d h dsinh dd pi;
Wetp d cos hd;
elseif h h && h d
Case : h h diameter
hd h;
C;
C CC sinC;
Ah dh d hd sin h d d;
A dCsin h d dh dd dh d A;
Wetp d cosd h dcosC;
Wetp d cosd h dcosC Wetp;
A A;
Wetp Wetp;
elseif d h && h d
Case : diameter h diameter
h d ;
C;
C CC sinC;
Ah dh d hd sin h d d;
Ah dh d hd sin h d d A;
Wetp d cosd h dcosC;
Wetp d cos h d pi Wetp;
A A;
Wetp Wetp;
else
errorInvalid input for flow depth h;
end
Calculate hydraulic radius, velocity, and flow rate
Output wetted perimeter and crosssectional area
P Wetp;
A A;
end
function V Q VQd h n s
P A horseshoeFlowd h;
RAP;
V n R sqrts;
dispV;
QVA;
dispQ;
end
filename inputEnter file name: s;
Read data from the specified file
data readDatafilename;
Extract values from the structure
d data.DIAMETER;
h data.DEPTH;
n data.MANNING;
s data.SLOPE;
Call the horseshoeFlow function with the obtained values
V Q VQd h n s;
example for dat file:MANNING:
DIAMETER: #m
SLOPE: # per cent actual slope is
DEPTH: #m
DISCHARGE: #msec
MATLAB CODE ON
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started