I have a function and I would like for it to print out an answer if I feed it a value.
조회 수: 2 (최근 30일)
이전 댓글 표시
I am using the Colebrook equation, which is a function of "f" and "Re" PLEASE READ(RE IS WHERE 126,400 IS). I haven't used MATLAB in a long time. Basically if I plug in a value for f into the equation, I get a value for Re. I need to do this for f = 0:0.0001:1 (which is a 10000x1 double) so I'll get the respective values for Re with respect to f = 0:0.0001:1. How do I go about doing this in MATLAB? I understand that I need to set the equation equal to zero, but I do not know what to do after that.
Here is the equation
댓글 수: 2
채택된 답변
Star Strider
2018년 5월 4일
Probably the easiest way is to have the Symbolic Math Toolbox solve for ‘Re’, then do the calculations in an anonymous function created by matlabFunction:
syms f Re
Eqn = 1/sqrt(f) == -2*log(4.2E-5/3.7 + 2.51/(Re*sqrt(f)));
Re_sol = solve(Eqn, Re);
ReFcn = matlabFunction(Re_sol)
f = linspace(0, 1, 1E+4);
figure
semilogy(f, ReFcn(f))
grid
xlabel('f')
ylabel('Re')
This produces:
ReFcn = @(f) (1.0./sqrt(f).*(2.51e2./1.0e2))./(exp(1.0./sqrt(f).*(-1.0./2.0))-1.135135135135135e-5);
You might want to use abs(ReFcn(f) in the plot, to avoid the ‘Warning: Negative data ignored’ message.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Values에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!