function handle error with matirx

3 次查看(过去 30 天)
i get the error below, any ideas where i've gone wrong? Also with the way i've wrote my D & L vectors will D(1) and the corresponding L(1) be used together in further calculations.
%F ZERO cannot continue because user supplied function_handle ==> %@(x)1/sqrt(x)+2*log10(eoverD/3.7+2.51/Re/sqrt(x))
%failed with the error below.
%Matrix dimensions must agree.
%Error in ==> Q1_check_2 at 22
%f = fzero(darbyFormula,4);
D = [0.1, 0.2, 0.05, 0.15];
L = [10, 3, 4, 8];
A = 0.25*pi.*D.^2;
e = 0.0015e-3;
rho = 998;
nu = 1.01e-6;
eoverD = e./D;
alpha = 0.1;
%
Vo = 2;
for Vn = 2:0.1:30;.
Re = (D.*Vo) / nu;
if Re < 2300
f = 64 / Re;
else
darbyFormula = @(x) 1/sqrt(x)+2*log10(eoverD/3.7 + 2.51/Re/sqrt(x));
f = fzero(darbyFormula,0.01);
end
%
dPloss = (f*rho*(L./D)) * ((Vn.*Vo)./2);
Va = (alpha*Vn)+((1-alpha)*Vo);
Vo = Va;
end

采纳的回答

the cyclist
the cyclist 2013-8-28
You cannot call fzero() with Re as a vector, in the way that you have done. You need to solve for each value of Re individually. (Also, your if statement will not work as you intend, as written.)
Rather than trying to do all values of (D,L) at once, I suggest you just write a loop over those values.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by