I am trying to assign only positive integers to a variable.
22 次查看(过去 30 天)
显示 更早的评论
I have an equation which returns positive and negative real and imaginary numbers. I have already separated the real part and assigned it to a variable "w", which now returns positive and negative real numbers. I only need the positive numbers assigned to "w" so that when "h" is solved the result is only positive real numbers.
L=15.7;
l=11.6;
Wab=20;
Wbd=40;
Mab = Wab/32.2;
Mbd = Wbd/32.2;
Wbd2=(Wbd/(L-1));
d=2.58;
OB=L-l-d;
BD=d+OB;
Wbo=Wbd2*OB;
Wod=Wbd2*d;
delta=d*0.95;
syms Wc
eqn = (((11.6/2)+1.52)*20)+((((15.6-11.6)/2)-1.52)*Wbo)-((d/2)*Wod)-(delta*Wc)==0;
S = solve(eqn);
Wc = eval(S)
Mc = Wc/32.2;
D=490*(1/32.2);
syms w
eqn = Mc*D==(4*(w.^3));
V = solve(eqn);
w1 = eval(V);
w = real(w1)
h=2*w
1 个评论
Star Strider
2022-11-25
Specify ‘w’ to be real, and then request 'ReturnConditions' on the evaluation to understand under what conditions ‘w’ will be real:
syms w real
eqn = Mc*D==(4*(w.^3));
V = solve(eqn, 'ReturnConditions',1)
That is likely the best you can do.
L=15.7;
l=11.6;
Wab=20;
Wbd=40;
Mab = Wab/32.2;
Mbd = Wbd/32.2;
Wbd2=(Wbd/(L-1));
d=2.58;
OB=L-l-d;
BD=d+OB;
Wbo=Wbd2*OB;
Wod=Wbd2*d;
delta=d*0.95;
syms Wc real
eqn = (((11.6/2)+1.52)*20)+((((15.6-11.6)/2)-1.52)*Wbo)-((d/2)*Wod)-(delta*Wc)==0;
S = solve(eqn)
% Wc = eval(S)
Mc = Wc/32.2;
D=490*(1/32.2);
syms w real
eqn = Mc*D==(4*(w.^3));
V = solve(eqn, 'ReturnConditions',1)
V.w
V.conditions
% w1 = eval(V)
% w = real(w1)
h=2*w
I leave you to explore those conditions at your leisure.
.
采纳的回答
Vilém Frynta
2022-11-25
Not sure if I understand correctly, but if you want to ignore the negative values, you can do:
w = [1.8 -0.9 -0.9]' % your values
w = w(w>0) % only positive values
Hope I helped, otherwise feel free to correct me or describe your problem.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!