Can't get my code to execute

2 ビュー (過去 30 日間)
N/A
N/A 2022 年 8 月 31 日
回答済み: Karim 2022 年 8 月 31 日
So I was given this question to work on.
I tried to work on the code into mathlab and plot the graph but can't seem to execute and have no idea where go wrong. This is what I have for now.
Any help is appreciated, thank you.
A=1.325;
B=3.7;
C=5.74;;
D=[10.^-6:10.^-2] %Relative Roughness range
E=[108:4000]; %Reynolds number
f=A/log((1/3.7)*D+(C/E.^0.9)).^2; %Given Swamee-Jain formula
figure(5);
plot(D, f);
xlabel('Reynolds Number');
ylabel('Friction Factor f');
title('Friction Factor against Reynolds Number');
grid on

採用された回答

Karim
Karim 2022 年 8 月 31 日
There were some minor mistakes, see below for the code with inline comments to explain the differences.
A = 1.325;
B = 3.7;
C = 5.74;
% number of e/d values, set to 3 as in the question
nD = 3;
% Relative Roughness range
D = linspace(10.^-6,10.^-2,nD);
% Reynolds number range
E = 108:4000;
% initialize a matrix for the friction factor values, as many rows as the
% ralative roughness range and as many columns as the reynolds number range
f = zeros( nD , numel(E) );
% evaluate the Swamee-Jain formula, in a loop, iterate over the relative
% roughness range
for i = 1:nD
f(i,:) = A ./ log( (1/3.7)*D(i)+(C./E.^0.9) ).^2;
% note that here we use ./ and .^ for element wise operations
end
figure
plot(E, f);
xlabel('Reynolds Number')
ylabel('Friction Factor f')
title('Friction Factor against Reynolds Number')
grid on

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by