How can I solve a cubic equation in which the coefficients are vector arrays?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
letoppina
am 9 Jul. 2018
Beantwortet: letoppina
am 11 Jul. 2018
Hi everyone,
My intention is to find the roots of a cubic function. My only problem is that each coefficient is a vector array (1x30). 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 1x30. How can I do that? I have tried by making a loop but there is still something wrong.
2 Kommentare
Stephan
am 9 Jul. 2018
Hi,
please share your code by inserting it, mark it and press the {}Code button, so that it looks like this:
A = Your code
Best regards
Stephan
Akzeptierte Antwort
Weitere Antworten (1)
Shantanu Gontia
am 10 Jul. 2018
You can find the roots for the polynomial inside the loop itself. I'm assuming that only one root will satisfy the criteria of being positive and greater than 0.1. Here is a sample code implementing this
R = linspace(1000,100e4,30); %I create my array
% Declare roots array (initialize with zeros)
r = zeros(1, 30); % 30 roots
for ii = 1:length(R)
%coefficients of my polyonmial equation (they are all in function of R(ii) so that they are all arrays)
a(ii) = CONSTANT*R(ii);
b(ii) = CONSTANT*R(ii);
c(ii) = CONSTANT*R(ii);
d(ii) = CONSTANT*R(ii);
p = [a(ii) -b(ii) -c(ii) d(ii)];
rts = roots(p); % Get the roots
rts = rts(rts > 0.1); % Get the roots satisfying the criteria
r(ii) = rts(1); % Get one of the roots (if more than one)
end
4 Kommentare
Siehe auch
Kategorien
Mehr zu Interpolation 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!