blob: dc78f95711ff6565336c06082bd7af9bdeea076e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
//Author: Parthasarathi Panda
//parthasarathipanda314@gmail.com
function [zerosort,g]=sosbreak(p)
//function for breaking a polynomial in second order polynomials (and an extra linear)
[zero,g]=factors(p);//factorising into real coefficient polynomials
degn=degree(p);
zerosort=list();
//to segregate linear and quadratic factors
for i=[1:length(zero)]
q=zero(i);
//putting the quadratic factor at the front
if degree(q)==2 then
zerosort(0)=q;
//putting the linear factor at the end
else
zerosort($+1)=q;
end
end
if (modulo(degn,2))==0 then
e=length(zerosort);
//leave the last linear element if an odd degree polynomial
else
e=length(zerosort)-1;
end
for i=[e:-2:1]
q=zerosort(i);
if degree(q)==2 then
break;
end
zerosort(i)=q*zerosort(i-1);//combining 2 linear polynomial into one quadratic polynomial
zerosort(i-1)=null();//removing leftover linear polynomial
end
endfunction
|