将 matlab 内联命令转换为不同的

converting matlab inline command to different

本文关键字:转换 命令 matlab      更新时间:2023-10-16
我在 Matlab 中

工作,我编写了以下脚本,旨在导入到 Excel 中,但是当我运行 Matlab C++ Coder 时,它告诉我不支持我的内联命令。

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 命令,以便编译器正常工作?

findf = @(f,ed,Re( 1.0/sqrt(f(

+2.0*log10(ed/3.7+2.51/(Re*sqrt(f

(((