function handle error with matirx

2 Ansichten (letzte 30 Tage)
harley
harley am 28 Aug. 2013
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

Akzeptierte Antwort

the cyclist
the cyclist am 28 Aug. 2013
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.
  1 Kommentar
harley
harley am 28 Aug. 2013
thanks, i'll write D,L into the loop.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by