Help with Colebrook equation and f zero command.

I am trying to do a problem with the colebrook equation in which I have to find the roots of the equation to find "f". I am trying to use the fzero command along with a function file, but it is not working. How do I do this?
function f = fricfactor(f) Re = linspace(10e4,10e7,31); f = (1/sqrt(f))-2*log10(Re*sqrt(f))-0.8; end
fcw = fzero(@fricfactor,[0 1]);

 채택된 답변

Torsten
Torsten 2014년 11월 7일

0 개 추천

f=@(x)(1/sqrt(x)-2*log10(Re*sqrt(x))-0.8);
Re=10000;
Delta_Re=200;
for i=1:20
fcw(i)=fzero(f,[1e-8 1]);
Reynolds(i)=Re;
Re=Re+Delta_Re;
end
Best wishes
Torsten.

댓글 수: 3

Yianni
Yianni 2014년 11월 7일
Thank you!
Yianni
Yianni 2014년 11월 7일
Im actually getting this error when I do this:
Error: File: prac.m Line: 10 Column: 15 "f" was previously used as a variable, conflicting with its use here as the name of a function or command. See "How MATLAB Recognizes Command Syntax" in the MATLAB documentation for details.
Yianni
Yianni 2014년 11월 7일
I get this specifically for your work:
Operands to the and && operators must be convertible to logical scalar values.
Error in fzero (line 423) while fb ~= 0 && a ~= b
Error in prac2 (line 9) fcw(i)=fzero(f,[1e-8 1]);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2014년 11월 7일

0 개 추천

Re=10000;
f=@(x)(1/sqrt(x)-2*log10(Re*sqrt(x))-0.8);
fcw = fzero(f,[1e-8 1]);
If you want to determine fcw for different Reynolds numbers, you will have to do that in a for Loop.
Best wishes
Torsten.

댓글 수: 1

Yianni
Yianni 2014년 11월 7일
Yes I want to use a looping structure, but where could I do this in this function file?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

질문:

2014년 11월 7일

댓글:

2014년 11월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by