Trying to create an array
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2020년 4월 18일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!