MATLAB: How to get the positive root of the cubic a*x^3+3*b*x^2+3*c*x+d=0

rootzeros

How to get the positive root of the cubic a*x^3+3*b*x^2+3*c*x+d=0 where a=1,c=b+2, d=-3 and b=.1:.1:2.
If rr is the root, find rr/(rr+1) for each b.

Best Answer

You can try
b = .1:.1:2;
a = 1;
c = b+2;
d = -3;
posR = zeros(1,length(b));
for i = 1:length(b)
r = roots([a,3*b(i),3*c(i),d]);
posR(i) = r(r>0); % only one real root for the values you specified
posR(i) = posR(i)/(posR(i)+1);
end