Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i have these matlab codes :function [ P , A ] = horseshoeFlow ( d , h , n , s ) % Constants %
i have these matlab codes :function P A horseshoeFlowd h n s
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
Rh A Wetp;
V n Rhs;
Q V A;
Output wetted perimeter and crosssectional area
P Wetp;
A A;
end
function data readDatafilename
filename'mixdat'
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
Call readData function to get values from the dat file
data readDatamixdat';
Extract values of d h and n from the structure
d data.DIAMETER; Assuming 'DIAMETER' is the parameter for diameter
h data.DEPTH; Assuming 'DEPTH is the parameter for flow depth
n data.MANNING;
s data.SLOPE; Assuming 'MANNING' is the parameter for Manning's n
Call the horseshoeFlow function with the obtained values
P A horseshoeFlowd h n s;
Display the results
fprintfWetted Perimeter P: f
P;
fprintfCrosssectional Area A: f
A;
which reads the mixdat files and gives me A nd P
How can I modify thse codes so that it can read multiple dat files with almost the same structure and with the 'input' command I can write which dat file I want it to take the data from and calculate A and P
for example I have mixdat:MANNING:
DIAMETER: #m
SLOPE: # per cent actual slope is
DEPTH: #m
DISCHARGE: #msec and mixdat:#Petaloid section
DIAMETER: #m
MANNING:
SLOPE: # per cent actual slope is
#DEPTH: #m
DISCHARGE: #msec
when I run the programm: enter file prefix:mixdat
and it gives me A and P for mixdat
thanks!MATLAB CODE ONLY!!
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