clear all;
clc;
data8={'1','10','20','23','12','11'};
kk{1}='Internal pipe roughness (mm)';
kk{2}='Hydraulic diameter of pipe (m)';
kk{3}='Reynolds number ';
kk{4}='Pipe line length (m)';
kk{5}='Average pipe line velosity (m/s)';
kk{6}='Acceleration due to gravity (m/s^2)';
kkk=inputdlg(kk,'Head loss',1,data8);
e11=str2num(kkk{1});
d12=str2num(kkk{2});
re1=str2num(kkk{3});
l2=str2num(kkk{4});
v11=str2num(kkk{5});
g12=str2num(kkk{6});
eqn=(1/sqrt(f9)==(-2*log((e11/3.7*d12)+(2.51/re1*sqrt(f9)))));
solve('eqn','sqrt(f9)');
hf=(f12*l2*(v11^2))/(2*g12*d12);
fprintf('Friction factor in pipe = %f \n Head loss = %f (m) \n-----------------------------------------------\n',f1,hf);
Undefined function or variable 'f9'.
Error in Untitled (line 150)
eqn=(1/sqrt(f9)==(-2*log((e11/3.7*d12)+(2.51/re1*sqrt(f9)))));

2 commentaires

e11=str2num(kkk{1});
d12=str2num(kkk{1});
re1=str2num(kkk{1});
l2=str2num(kkk{1});
v11=str2num(kkk{1});
g12=str2num(kkk{1});
are you sure that you want to use kkk{1} as the source for all of those str2num() ? That assigns the same value to each of the variables.
hadi mohammadian
hadi mohammadian le 30 Déc 2020
Modifié(e) : hadi mohammadian le 30 Déc 2020
yes . you're right . I changed them . thanks alot .
in matlab they're correct but they were wrong in here .

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 30 Déc 2020
syms f9 f9sqrt
eqn=(1/sqrt(f9)==(-2*log((e11/3.7*d12)+(2.51/re1*sqrt(f9)))));
F9sqrt = solve(subs(eqn, f9, f9sqrt^2), f9sqrt)

5 commentaires

hadi mohammadian
hadi mohammadian le 30 Déc 2020
thanks . but no.
the eror still there .
hadi mohammadian
hadi mohammadian le 30 Déc 2020
in direct words , I gave all values to program (with inputdlg so the user able to change numbers) and I want to program solve the equation and give me the value of (f9) , so I can use it in other equations . that's all .lol
e11 = 1;
d12 = 10;
re1 = 20;
i2 = 23;
v11 = 12;
g12 = 11;
syms f9sqrt
eqn=(1/f9sqrt==(-2*log((e11/3.7*d12)+(2.51/re1*f9sqrt))));
sol1 = vpasolve(eqn, f9sqrt, -15)
sol2 = vpasolve(eqn, f9sqrt, -1)
The results are -13.261186218170519738583506098119 and -0.51544996325405629560226567032353 . Those are the square roots of the values, so f9 itself will be complex valued
Please re-check whether the expression should be (2.51/re1)*sqrt(f9) like you have coded, or if it should instead be 2.51/(re1*f9sqrt) . If it is the second of those, there is a closed form solution involving WrightOmega that leads to sqrt(f9) about -0.5517 (also complex valued.)
hadi mohammadian
hadi mohammadian le 30 Déc 2020
thanks man . my issue solved .
Walter Roberson
Walter Roberson le 30 Déc 2020
What was the solution ?

Connectez-vous pour commenter.

Plus de réponses (1)

Alan Stevens
Alan Stevens le 30 Déc 2020
Strange way of entering data! However, one way to find the friction factor is a simple fixed point iteration method, such as
e11 = 1;
d12 = 10;
re1 = 20;
l2 = 23;
v11 = 12;
g12 = 11;
f9 = 1; % initial guess
tol = 10^-6;
err = 1;
% fixed point iteration
while err>tol
f9old = f9;
f9 = (-2*log10(e11/(3.7*d12)+2.51/(re1*sqrt(f9))))^-2;
err = abs(f9-f9old);
end
disp(f9)
Note that I've used log10 rather than log (the latter is log to the base e).

1 commentaire

hadi mohammadian
hadi mohammadian le 30 Déc 2020
thanks man .
but It's not I'm looking for .
and the log10 don't path the eror .

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by