Left and right sides have different number of elements

조회 수: 1 (최근 30일)
Karlie Brillant
Karlie Brillant 2019년 4월 24일
답변: Star Strider 2019년 4월 24일
Getting an error in line 5 of my script,
counter=1;
for R_e=linspace(1*10^3,1*10^5,10)
k=linspace(1*10^-6,1*10^-3,10);
f(counter)=pipe(R_e,k);
counter=counter+1;
end
This is where I am calling my function (seen below), but I am getting an error that the left and right sides have a different number of elements. I need to fun my function for all values of R_e and k (to get 100 f values total), not sure my script will do that properly because it is getting stuck trying to call the function. I have done something similar in the past and cannot figure out where I messed up.
function f=pipe(R_e,k)
dh=0.1;
guess_f=64/R_e;
f1=(2*log((2.51/R_e*(guess_f).^0.5)+((k/dh)/3.72))).^-2;
df=0.1;
guess_f=guess_f+df;
f2=(2*log((2.51/R_e*(guess_f).^0.5)+((k/dh)/3.72))).^-2;
change_in_f=abs((f1-f2)/f1);
f2=guess_f+change_in_f;
while change_in_f>=1e-5
f=(2*log((2.51/R_e*(f2).^0.5)+((k/dh)/3.72))).^-2;
change_in_f=abs((f-f2)/f);
f2=f;
end
end

채택된 답변

Star Strider
Star Strider 2019년 4월 24일
Both ‘R_e’ and ‘k’ are (1 x 10) vectors, so ‘f’ will also be a (1 x 10) vector.
Try this:
f(counter,:)=pipe(R_e,k);
With that change, your code ran without error for me.
Experiment to get the result you want.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by