I am trying to assign only positive integers to a variable.
16 ビュー (過去 30 日間)
古いコメントを表示
Amanda Garcia-Menocal
2022 年 11 月 25 日
コメント済み: Star Strider
2022 年 11 月 25 日
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!