MATLAB: How to solve a cubic equation in which the coefficients are vector arrays

coefficientscubiccubic euqationrootsvector arraysvectors

Hi everyone,
My intention is to find the roots of a cubic function. My only problem is that each coefficient is a vector array (1×30). Also, I want to take only the positive roots (and bigger than 0.1) so that in the end also the resulting roots vector has a dimension of 1×30. How can I do that? I have tried by making a loop but there is still something wrong.

Best Answer

So in the end I have figured it was just a way to declare my variables. Here below my working code:
R = linspace(1000,100e4,30); %I create my array
rts = zeros(3, length(R)); %inizialization of rts (matrix of the roots --> it,s a cubic equation, so three roots for each component of the arrays)
for ii = 1:length(R)
a(ii) = CONSTANTS*R(ii);
b(ii) = CONSTANTS*R(ii);
c(ii) = CONSTANTS*R(ii);
d(ii) = CONSTANTS*R(ii);
p = [a1(ii) -b1(ii) -c1(ii) d1(ii)];
rts(:,ii) = roots(p); %find the roots of the polynomial equation
end
coeff = rts.*(rts>0.1); %condition that I put in order to exctact only the parameters that I need