How can I solve my for
1 view (last 30 days)
Show older comments
Maria ines Barba Sarasua
on 31 May 2023
Answered: Walter Roberson
on 31 May 2023
Hello, I have this error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
C = privsubsasgn(L,R,inds{:});
My code is the following one:
clear all
clc
syms x
Caudal=[5.93266E-05, 0.00082573, 0.001571951, 0.002318172, 0.003064541, 0.004018053, 0.00493061, 0.005552929, 0.006549172, 0.007338123, 0.008085823, 0.008833522, 0.009415033, 0.009996545, 0.010868442, 0.011574151, 0.012196174, 0.013025341, 0.013895908, 0.014848681, 0.015801455, 0.017251758, 0.018371164, 0.019200479, 0.019781399, 0.02036254, 0.020860957, 0.021234807, 0.021691677];
Presion=[1.638232756, 1.618669688, 1.579773777, 1.540877866, 1.496456555, 1.446449258, 1.379877876, 1.329967516, 1.230219498, 1.141582866, 1.047432951, 0.953283036, 0.881283191, 0.809283346, 0.71509708, 0.643060884, 0.604201324, 0.559755779, 0.515298116, 0.492917821, 0.470537526, 0.420384823, 0.359278257, 0.309307311, 0.259409068, 0.201222724, 0.140297914, 0.093222956, 0.037835664];
v_c=0.0000174/1.19;
A_disipador=0.095*0.002*45;
for M=1:numel(Caudal)
V_Disipador=(Caudal/A_disipador);
Re=(V_Disipador*0.039)/(v_c);
f(M)=vpasolve((1/sqrt(x)==-2*log((0.502/0.095)/3.7+2.51/(Re(M)*sqrt(x))))) %HERE IS THE ERROR
h=f*(0.095/0.0039)*((1.3048).^2/(2*9.81))
end
0 Comments
Accepted Answer
Walter Roberson
on 31 May 2023
syms x
Caudal=[5.93266E-05, 0.00082573, 0.001571951, 0.002318172, 0.003064541, 0.004018053, 0.00493061, 0.005552929, 0.006549172, 0.007338123, 0.008085823, 0.008833522, 0.009415033, 0.009996545, 0.010868442, 0.011574151, 0.012196174, 0.013025341, 0.013895908, 0.014848681, 0.015801455, 0.017251758, 0.018371164, 0.019200479, 0.019781399, 0.02036254, 0.020860957, 0.021234807, 0.021691677];
v_c=sym(0.0000174)/sym(1.19);
A_disipador=sym(0.095)*sym(0.002)*sym(45);
for M=1:numel(Caudal)
V_Disipador=(Caudal(M)/A_disipador);
Re=(V_Disipador*sym(0.039))/(v_c);
eqn = (1/sqrt(x)==-2*log((sym(0.502)/sym(0.095))/sym(3.7)+sym(2.51)/(Re*sqrt(x))))
f{M} = vpasolve(eqn); %HERE IS THE ERROR
h{M} = f{M}*(sym(0.095)/sym(0.0039))*(sym(1.3048).^2/(2*sym(9.81)));
end
f
Look at the equation. The constant beign added inside the log() is more than 1, so provided the ratio divided by sqrt(x) is not negative, then the value inside the log() must be greater than 1, so the log must be positive. Positive log multiplied by negative 2 is going to be negative, and if x is positive then sqrt(x) is never negative so 1/sqrt(x) is never negative. We thus conclude that if x is positive then the equation cannot hold.
What if x is negative? Then sqrt(x) would be complex valued and you would be taking log of a complex value and trying to match it to -1i / sqrt(-x) . Can those be equal? I suspect not, but I have not investigated to prove it.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!