Help with Colebrook equation and fzero command.

4 ビュー (過去 30 日間)
Yianni
Yianni 2014 年 11 月 7 日
編集済み: Dong Young Kim 2019 年 5 月 10 日
I am trying to do a problem with the colebrook equation in which I have to find the roots of the equation to find "f". I am trying to use the fzero command along with a function file, but it is not working. How do I do this?
Re = linspace(10e4,10e7,NRe); NRe = 31; %Values for Reynold's Numbers
F = 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f)); %Colebrook Equation
fcw = fzero(@fricfactor,1,2); %Attempt at fzero command
  2 件のコメント
John D'Errico
John D'Errico 2014 年 11 月 7 日
編集済み: John D'Errico 2014 年 11 月 7 日
This is your second question I've seen about fzero from you. In the last question, you used a loop around fzero (although you do not yet seem to accept that no solution exists for that particular problem.) Is there some reason why a loop did not seem right here?
fzero does not solve multiple problems at once. Yes, it is true that careful use of arrayfun would succeed here, there is no need to use a complicated function syntax when a trivial loop would suffice. Learn to solve problems using the basic tools, and only when you clearly understand the language does it make sense to proceed to the complex.
Yianni
Yianni 2014 年 11 月 8 日
編集済み: per isakson 2014 年 11 月 8 日
I figured out how to do this with one value of Re. See below:
% parameterized function
F = @(f,Re) 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f));
Re = 1e4 % parameter
fun = @(f) F(f,Re); % function of x alone
x = fzero(fun,0.1)
However, I still cannot figure out how to do the looping structure. This is my approach:
Re = linspace(1e4,1e7,31);
NRe =length(Re);
F = zeros(size(Re));
for i = 1:NRe
% parameterized function
F(i) = @(f,Re) 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f));
end
fun = @(f) F(f,Re); % function of x alone
x = fzero(fun,0.1);

サインインしてコメントする。

回答 (1 件)

Dong Young Kim
Dong Young Kim 2019 年 5 月 10 日
編集済み: Dong Young Kim 2019 年 5 月 10 日
It can be ran with following
% parameterized function
Ret=3000:1000:1000000;
NRe=length(Ret);
for i=1:NRe
F = @(f,Re) 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f));
Re = Ret(i); % parameter
fun = @(f) F(f,Re); % function of x alone
ft(i) = fzero(fun,0.1);
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by