int main() { array double x1[3], p1[4] = {1, -6, -72, -27}; /* x^3-6x^2-72x-27 =0*/ array double x2[4], p2[5] = {1, -12, 0, 25, 116}; /* x^4-12x^3-25x+116 =0 */ array double complex z2[4], zp2[5]; array double complex z3[4], p3[5] = {complex(3,4), complex(4,2), complex(5,3), complex(2,4), complex(1,5)}; int status; roots(x1, p1); polycoef(p1, x1); printf("p1 from polycoef(p1, x1) = %f\n", p1); /* x^4-12x^3-25x+116 =0 has two complex roots and two real roots */ roots(x2, p2); roots(z2, p2); polycoef(p2, x2); printf("p2 from polycoef(p2, x2) = %f\n", p2); polycoef(zp2, z2); printf("zp2 from polycoef(zp2, z2) = %f\n", zp2); roots(z3, p3); status = polycoef(p3, z3); if(status == 0) { printf("p3 from polycoef(p3, z3) = %f\n", p3); printf("complex(3,4)*p3 from polycoef(p3, z3) = %f\n", complex(3,4)*p3); roots(z3, p3); printf("z3 from roots(z3, p3) = %f\n", z3); } else printf("polycoef(p3, z3) failed\n"); }
p1 from polycoef(p1, x1) = 1.000000 -6.000000 -72.000000 -27.000000 p2 from polycoef(p2, x2) = 1.000000 NaN NaN NaN NaN zp2 from polycoef(zp2, z2) = complex(1.000000,0.000000) complex(-12.000000,0.000000) complex(0.000000,0.000000) complex(25.000000,0.000000) complex(116.000000,0.000000) p3 from polycoef(p3, z3) = complex(1.000000,0.000000) complex(0.800000,-0.400000) complex(1.080000,-0.440000) complex(0.880000,0.160000) complex(0.920000,0.440000) complex(3,4)*p3 from polycoef(p3, z3) = complex(3.000000,4.000000) complex(4.000000,2.000000) complex(5.000000,3.000000) complex(2.000000,4.000000) complex(1.000000,5.000000) z3 from roots(z3, p3) = complex(0.226342,1.281483) complex(0.431121,-0.728039) complex(-0.754085,-0.707780) complex(-0.703378,0.554336)