开发者

solution of an implicit equation with fzero on MATLAB

开发者 https://www.devze.com 2023-02-25 19:52 出处:网络
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.

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 开发者_如何学JAVAthis 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.


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

精彩评论

暂无评论...
验证码 换一张
取 消