Left and right sides have different number of elements

1 visualización (últimos 30 días)
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

Respuesta aceptada

Star Strider
Star Strider el 24 de Abr. de 2019
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.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by