MATLAB: Hey guys can anyone help me to see where I am wrong in the code? I have to get the unknowns within the ranges of 02300. I have attached the code so far.

MATLABmechanical engineering

Original Equations to solve for Unknowns are:
1. V=0.35/((pi*D^2)/4)
2. Re=(VD)/0.00001265
3. 20=f*(150/D)*((V^2)/(2*9.81))
4. 1/sqrt(f)=-log_10(2.51/(Re*sqrt(f)))
My code is as follows:
syms V D Re f
V=[0 50]
D=[0 10]
f=[0 1]
Re>2300
%declaring equations
eqn1 = (V*pi*D.^2)/1.4 == 0;
eqn2 = Re * 0.00001265 – V*D == 0
eqn3 = 20*D*2*9.81 – 150*f*V.^2 == 0
eqn4 = 1/sqrt(f) + log10(2.51/Re*sqrt(f)) == 0
sol = solve([eqn1, eqn2, eqn3, eqn4], [V,D,Re, f]);
vSol = vpa(sol.V, 3)
dSol = vpa(sol.D, 3)
ReSol = vpa(sol.Re, 3)
fSol = vpa(sol.f, 3)
%displaying results
disp(vSol)
disp(dSol)
disp(ReSol)
disp(fSol)

Best Answer

Use the vpa funciton:
... CODE ...
vSol = vpa(sol.V, 3)
dSol = vpa(sol.D, 3)
ReSol = vpa(sol.Re, 3)
fSol = vpa(sol.f, 3)
vSol =
0.00169
dSol =
16.2
ReSol =
2177.0
fSol =
7.45e5
0.00169
16.2
2177.0
7.45e5
EDIT
The Symbolic Math Toolbox is likely not the best option if you want to impose constraints. Creating an anonymous function (see the appropriate section in Function Basics) from your equations and using the fmincon function would probably do what you want.