MATLAB: How to use an if loop to display a message with displaying the positive value of D and ignoring the negative ones

if else loop

roots([1/16 23/8 0 (9/2-5000/pi)])
ans =
-32.8324 +14.6054i
-32.8324 -14.6054i
19.6648 + 0.0000i
D=real(d)
D =
-32.8324
-32.8324
19.6648

Best Answer

This works:
D = roots([1/16 23/8 0 (9/2-5000/pi)])
Dp = D(D > 0) % Positive root
Dr = D(imag(D) == 0) % Real root
Dp is the positive root, and if you want the real root, it is Dr.