MATLAB: I still have errors in the code and would like help in fixing these errors. I have to get the unknowns within the ranges of 02300. I have attached the code so far along with the equations given to be solved

engineeringmathmathematicsMATLABmechanical engineering

I also need to create a graph of errors. Original Equations to solve for Unknowns are:
V=0.35/((pi*D^2)/4)
Re=(VD)/0.00001265
20=f*(150/D)*((V^2)/(2*9.81))
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

Re>2300
is just going to display the same thing. Your Re is symbolic so the result of that calculation is going to be a symbolic inequality that will then be displayed (because the line does not end in semi-colon) and then discarded (because you do not assign to a variable.) If you are trying to create a constraint, then you should be using assume()
You have
V=[0 50]
D=[0 10]
and then
eqn1 = (V*pi*D.^2)/1.4 == 0;
With V being a 1 x 2 vector, V*Pi is going to be a 1 x 2 vector. D is a 1 x 2 vector so D.^2 is a 1 x 2 vector. Now you have a 1 x 2 vector "*" a 1 x 2 vector. But the "*" operator is linear algebra matrix multiplication, so the "inner dimensions" must agree -- you can multiply a 1 x 2 by a 2 x 1 (getting a 1 x 1 result) or you can multiply a 2 x 1 by a 1 x 2 (getting a 2 x 2 result), but you cannot multiply a 1 x 2 by a 1 x 2.
Perhaps you want the .* operator instead of the * operator, to do element-by-element multiplication.
eqn1 = (V.*pi.*D.^2)./1.4 == 0;
However, you used constants for V and D, so everything in the (V.*pi.*D.^2)./1.4 expression is going to have a fixed numeric result, which you then compare to 0. The result is going to be a 1 x 2 logical vector, not an equation.