I am trying to assign only positive integers to a variable.
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Amanda Garcia-Menocal
am 25 Nov. 2022
Kommentiert: Star Strider
am 25 Nov. 2022
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 Kommentar
Star Strider
am 25 Nov. 2022
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.
.
Akzeptierte Antwort
Vilém Frynta
am 25 Nov. 2022
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!