Trying to create an array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Daniel Zalivchi
le 18 Avr 2020
Commenté : Star Strider
le 19 Avr 2020
So I have this array with 2 conjugate pairs and 1 real value
sp =
-0.0895 + 0.9901i
-0.0895 - 0.9901i
-0.2342 + 0.6119i
-0.2342 - 0.6119i
-0.2895 + 0.0000i
I'm trying to create another array called P(k)
with the 3 equations P1, P2,and P3
The equation for the conjugate pairs is
P(k) = (s - sp1(k)) * (s - sp2(k))
where sp1 is the first complex number of the pair and sp2 is the second complex number of the pair
Ex:
sp1 = -0.0895 + 0.9901i
sp2 = -0.0895 - 0.9901i
The equation for real numbers
P(k) = (s - sp(k))
where sp(k) is that given real value
Ex:
sp = -0.2895 + 0.0000i
The answer is
P = [s^2 + 0.1789s +0.9883,
s^2 +0.4684s +0.4293,
s + 0.2895]
I TRIED THIS:
syms s
Ns = 3
%Complex Roots
X = sp(imag(sp)~=0);
S = isreal(X)
%Real Roots
Y = sp(imag(sp)==0);
T = isreal(Y)
for k = 1:Ns
if T == 0
P(k) = vpa(simplify((s-X(2*k-1))*(s-X(2*k))))
else
P(k) = vpa(simplify(s-Y(k-2)))
end
end
0 commentaires
Réponse acceptée
Star Strider
le 18 Avr 2020
Try this:
sp = [
-0.0895 + 0.9901i
-0.0895 - 0.9901i
-0.2342 + 0.6119i
-0.2342 - 0.6119i
-0.2895 + 0.0000i];
for k = 1:2:numel(sp)
ixr = unique(min([1 2]+(k-1),numel(sp)))
p = poly(sp(ixr))
if all(p ~= 0)
ki = ceil(k/2);
P{ki,:} = p;
end
end
syms s
for k = 1:numel(P)
Ps(k,:) = poly2sym(P{k},s);
end
Ps = vpa(Ps,4)
producing:
Ps =
s^2 + 0.179*s + 0.9883
s^2 + 0.4684*s + 0.4293
s + 0.2895
.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!