solution of an implicit equation with fzero on MATLAB

穿精又带淫゛_ 提交于 2020-01-03 03:10:50

问题


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);

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);

What is my mistake?

Thank you.


回答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.

Thus, your call to fzero should look like:

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

And the first line of coolebrookfunc has to be

function F = colebrookfunc(x,eD,Re)


来源:https://stackoverflow.com/questions/5688510/solution-of-an-implicit-equation-with-fzero-on-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!