Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.
|
|
Alex
Posts:
14
Registered:
12/18/13
|
|
Even/Odd polynomial
Posted:
Dec 19, 2013 2:22 PM
|
|
Given the transfer function p(s)=b(s)/a(s).
a(s)= ae(s^2)+s*ao(s^2); b(s)=be(s^2)+s*bo(s^2).
where the ae and be are the even polynomials and ao and bo are the odd polynomial. An example:
p(s)=(s-1)/(s^3+6s^2+17s+18)
ae(s^2)=6s^2+18; s*ao(s^2)=s^3+17s => ao(s^2)=s^2+17; be(s^2)=-1; s*bo(s^2)=s =>bo(s^2)=1. The matlab code that i wrote is:
ae = []; ao = []; if mod(length(a),2) == 0 for i = 1: length(a) if mod(i,2) == 0 ae = [ae a(i)]; else ao = [ao a(i)]; end end else for i = 1: length(a) if mod(i,2) == 0 ao = [ao a(i)]; else ae = [ae a(i)]; end end end be = []; bo = []; if mod(length(b),2) == 0 for i = 1: length(b) if mod(i,2) == 0 be = [be b(i)]; else bo = [bo b(i)]; end end else for i = 1: length(b) if mod(i,2) == 0 bo = [bo b(i)]; else be = [be b(i)]; end end end
I wonder if someone guide me with a code with less lines. Thank you!
|
|
|
|