2017-04-05 50 views
1

我正在Matlab中工作,我寫了下面的腳本,目的是導入到Excel中,但是當我運行Matlab C++編碼器時,它告訴我我的內聯命令不受支持。將matlab內聯命令轉換爲不同

function f = moody(ed,Re) 
if Re<0 
error(fprintf('Reynolds number = %f cannot be negative',Re)); 
elseif Re<2000 
f = 64/Re; return  % laminar flow 
end 
if ed>0.05 
error(fprintf('epsilon/diameter ratio = %f is not on Moody chart',ed)); 
end 
findf = inline('1.0/sqrt(f)+2.0*log10(ed/3.7+2.51/(Re*sqrt(f)))','f','ed','Re'); 
fi = 1/(1.8*log10(6.9/Re+(ed/3.7)^1.11))^2; % initial guess at f 
dfTol = 5e-6; 
f = fzero(findf,fi,optimset('TolX',dfTol,'Display','off'),ed,Re);` 

我如何重寫使用匿名函數或arrayfun命令,這樣編譯器將工作findf = inline命令?

回答

0

findf = @(f,ed,Re)1.0/sqrt(f)+ 2.0 * log10(ed/3.7 + 2.51 /(Re * sqrt(f)))