在MATLAB上用fzero求解隐式方程 [英] solution of an implicit equation with fzero on MATLAB
问题描述
我一直在尝试通过在MATLAB中使用fzero
来求解该隐式方程.保存代码的文件名为"colebrook"
,到目前为止,我键入的内容如下.
I've been trying to solve this implicit equation by using fzero
in MATLAB. File that holds the code is named as "colebrook"
and I've typed so far is as below.
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);
我要求解的方程式保存在另一个名为"colebrookfunc"
的m文件中,其包含的代码如下.
Equation that I want to solve is kept in another m-file called "colebrookfunc"
, and the code it contains is as below.
function F = colebrookfunc(x)
F = x - 1./(-4 * log10(eD/3.7 + 1.256./(Re*x.^0.5))).^2;
我在跑步时遇到此错误:
When i run in i get this error(s):
??? 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);
我怎么了?
谢谢.
推荐答案
You have to pass colebrookfunc
as a function handle. Also, unless you define colebrookfunc
as a nested function (which you, apparently, don't), you need to somehow pass the parameters to the function.
因此,您对fzero
的呼叫应如下所示:
Thus, your call to fzero
should look like:
a = fzero(@(x)colebrookfunc(x,eD,Re),0.1)
coolebrookfunc
的第一行必须是
function F = colebrookfunc(x,eD,Re)
这篇关于在MATLAB上用fzero求解隐式方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!