1

我一直在尝试通过fzero在 MATLAB 中使用来解决这个隐式方程。保存代码的文件被命名为"colebrook",到目前为止我输入的内容如下。

D = input('Please enter the pipe diameter in meters: ');
V = input('Please enter the fluid velocity in m/s: ');
rho = input('Please enter fluid density in kg/m^3: ');
mew = input('Please enter fluid viscosity in kg/m*s: ');
Re = D*V*rho/mew;

eps = input('Enter absolute roughness in milimeters: ');
eD = eps/(D*1000);

a = fzero(colebrookfunc,0.1);
fprintf(a);

我要求解的方程保存在另一个名为 的 m 文件"colebrookfunc"中,其中包含的代码如下。

function F = colebrookfunc(x)
    F = x - 1./(-4 * log10(eD/3.7 + 1.256./(Re*x.^0.5))).^2;

当我运行时,我收到此错误:

??? Input argument "x" is undefined.

Error in ==> colebrookfunc at 2
F = x - 1./(-4 * log10(eD/3.7 + 1.256./(Re*x.^0.5))).^2;
Error in ==> colebrook at 28
a = fzero(colebrookfunc,0.1);

我的错误是什么?

谢谢你。

4

1 回答 1

3

您必须colebrookfunc作为函数句柄传递。此外,除非您定义colebrookfunc为嵌套函数(显然,您没有定义),否则您需要以某种方式将参数传递给函数。

因此,您的调用fzero应如下所示:

a = fzero(@(x)colebrookfunc(x,eD,Re),0.1)

第一行coolebrookfunc必须是

function F = colebrookfunc(x,eD,Re)
于 2011-04-16T18:14:30.853 回答