how can i make this function work with arrays?

i have this function which works great but whenever i input an array it says "matrix dimensions must agree"
function [f]=colebrook(R,k)
f=fzero(@(f) 1/sqrt(f)+2*log10(k/3.7+2.51/(R*sqrt(f))),[1e-18,1]);
end
what can i edit to make it work with arrays?

댓글 수: 1

Use the "dot" math operators for * and / for element-by-element operation instead of matrix.
See section on "Array vs Matrix Operations" in documentation or type
doc mtimes
doc rdivide

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

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 10일

0 개 추천

Elementwise operation:
...
f=fzero(@(f) 1./sqrt(f)+2*log10(k/3.7+2.51./(R*sqrt(f))),[1e-18,1]);
...

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2021년 6월 10일

댓글:

dpb
2021년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by