フィルターのクリア

Problems with using a loop structure within an fzero command.

1 回表示 (過去 30 日間)
Yianni
Yianni 2014 年 11 月 8 日
編集済み: per isakson 2014 年 11 月 8 日
I have a file which uses the fzero command and works just fine as it gives me values of x when Re is chosen. See below:
F = @(f,Re) 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f)); % parameterized function
Re = 1e7; % parameter
fun = @(f) F(f,Re); % function of x alone
x = fzero(fun,.05)
I am trying to use several scalar values for Re via a looping structure, but I am struggling to understand how to use it properly. My attempt is below:
F = @(f,Re) 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f)); % parameterized function
Re = linspace(1e4,1e7,31); % parameter
fCW = zeros(size(Re));
for k = 1:length(Re)
fCW(k) = fzero(@(f) F(Re(k), f), 0.05);
end
  3 件のコメント
per isakson
per isakson 2014 年 11 月 8 日
編集済み: per isakson 2014 年 11 月 8 日
Have you tried to plot F(f) for a few values of Re? See&nbsp ezplot
Yianni
Yianni 2014 年 11 月 8 日
Individually it works just fine, but the looping doesn't yield anything on a plot.

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

回答 (1 件)

per isakson
per isakson 2014 年 11 月 8 日
編集済み: per isakson 2014 年 11 月 8 日
First compare the order of the input arguments in
F = @(f,Re) 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f));
and in
fCW(k) = fzero( @(f) F( Re(k), f ), 0.05 );
then replace
fCW(k) = fzero( @(f) F( Re(k), f ), 0.05 );
by
fCW(k) = fzero( @(f) F( f, Re(k) ), 0.05 );
and the loop will return a vector of numbers
>> fCW = cssm()
fCW =
0.0309 0.0104 0.0093 0.0087 0.0084 0.0081
where
function fCW = cssm()
F = @(f,Re) 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f));
Re = linspace(1e4,1e7,6);
fCW = zeros(size(Re));
for k = 1:length(Re)
fCW(k) = fzero( @(f) F(f,Re(k)), 0.05 );
end
end
&nbsp
In response to comment
[fCW,fB,fSJ,Re] = cssm()
figure, semilogy( fCW, Re, 'd' )
where
function [fCW,fB,fSJ,Re] = cssm()
F = @(f,Re) 2*log10(Re*sqrt(f))-0.8-(1/sqrt(f));
Re = logspace( 4,7,31 );
fCW = zeros(size(Re));
fB = zeros(size(Re));
fSJ = zeros(size(Re));
for k = 1:length(Re)
fCW(k) = fzero( @(f) F(f,Re(k)), 0.05);
fB(k) = 0.3164/Re(k)^0.25;
fSJ(k) = 0.25/(log(5.74/Re(k)^0.9))^2;
end
end
  2 件のコメント
Yianni
Yianni 2014 年 11 月 8 日
Excellent this works great!
Now is there a way to incorporate two more equations in here?
fB(:,k)=0.3164/Re(k)^0.25;
fSJ(:,k)=0.25/(log(5.74/Re(k)^0.9))^2;
These do not use fzero and I want to be able to plot these three equations as Re vs. (fCW,fB, fSJ)
per isakson
per isakson 2014 年 11 月 8 日
編集済み: per isakson 2014 年 11 月 8 日
Did you try? Why
fB(:,k)
rather than
fB(k)
Right hand side
0.3164/Re(k)^0.25
returns a scalar

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by