Return only the positive values to be used in subsequent eqns
2 views (last 30 days)
Show older comments
Hello all,
I am trying to get matlab to only display, and assign the positive value attained from solving the syms of eqn... to be used in subsequent equations. It keeps displaying both. I have tried a couple of other ways Please help

Here is copy paste code if you are feeling super nice.
g= -32.3;
syms v t
eqn3 = v > 0;
eqn4 = t > 0;
eqn1 = 3 == v * cos (45) *t;
eqn2 = t == (2 * v * sind(45))/g ;
eqns =[eqn1,eqn2]
sol = solve([eqns],[v,t]);
vS = vpa(sol.v)
tS = vpa(sol.t)
sol = solve([eqn3,eqn4],[v,t])
vpos = vS(vS>=0);
tpos = tS(tS>=0);
vpos
tpos
I have also tried it this way
g= -32.3;
syms v t
eqn3 = v > 0;
eqn4 = t > 0;
eqn1 = 3 == v * cos (45) *t;
eqn2 = t == (2 * v * sind(45))/g ;
eqns =[eqn1,eqn2]
sol = solve([eqns],[v,t]);
vS = vpa(sol.v)
tS = vpa(sol.t)
if vS == vSpos(vS>=0)
vSpos = vS(vSol>=0);
vS= vSpos
end
vS
tS
0 Comments
Answers (1)
Alan Stevens
on 6 Feb 2021
Why not use
g = 32.3;
v = sqrt(3*g/(2*cosd(45)*sind(45)));
t = 2*v*sind(45)/g;
which will give you positive values immediately?
Incidentally, you probably want cosd(45), not cos(45).
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!