Left and right sides have different number of elements
10 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!