1 //
2 // poly_findroots_example.c
3 //
4 // test polynomial root-finding algorithm (Bairstow's method)
5 //
6
7 #include <stdio.h>
8 #include <math.h>
9
10 #include "liquid.internal.h"
11
main()12 int main() {
13 unsigned int n=6; // polynomial length (order+1)
14 unsigned int i;
15
16 // generate polynomial
17 float p[6] = {6,11,-33,-33,11,6};
18 float complex roots[n-1];
19
20 // print polynomial
21 printf("polynomial:\n");
22 for (i=0; i<n; i++)
23 printf(" p[%3u] = %12.4f\n", i, p[i]);
24
25 // compute roots of polynomial
26 polyf_findroots(p,n,roots);
27 printf("roots:\n");
28 for (i=0; i<n-1; i++) {
29 printf(" r[%3u] = %12.8f + j*%12.8f\n", i,
30 crealf(roots[i]),
31 cimagf(roots[i]));
32 }
33
34 printf("done.\n");
35 return 0;
36 }
37