Effacer les filtres
Effacer les filtres

function handle error with matirx

1 vue (au cours des 30 derniers jours)
harley
harley le 28 Août 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

Réponse acceptée

the cyclist
the cyclist le 28 Août 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 commentaire
harley
harley le 28 Août 2013
thanks, i'll write D,L into the loop.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by