필터 지우기
필터 지우기

function handle error with matirx

조회 수: 1 (최근 30일)
harley
harley 2013년 8월 28일
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.
  댓글 수: 1
harley
harley 2013년 8월 28일
thanks, i'll write D,L into the loop.

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

추가 답변 (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