function handle error with matirx
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
the cyclist
il 28 Ago 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!