simpleCPQ.c


#include <stdio.h>
#include <math.h>
/*  *** SAMPLE PROGRAM: file: simpleCPQ.c   		*** 
   test_direct.c:  makes use of the fortran subroutine 
   CPQR79_(ndeg, coeff, root, ierr, work) which finds
   zeros of a polynomial.

   numbers are assumed complex and the the highest term is 
   coeff[0] z^ndeg. the constant term is coeff[ndeg+1]
*/
#define REAL float
#define DD 	48
/*   DD =  (2 ndeg) (ndeg+1) x [REAL]  = 4 3 = 12  	*/

struct complex {REAL re; REAL im;};

void cpqr79(int*, struct complex*, struct complex*,int*,REAL*);

int main() {
/* variables needed to pass to fortran function: 	*/
  int ndeg[1];
  int ierr[1];
  struct complex coeff[3];
  struct complex root[2];
 REAL work[DD];
/* variables for main(): 				*/
  int i=0;
  REAL f;
/* define our polynomial; a simple quadratic (z+1)(z+2)	*/
 coeff[0].re=1.; coeff[0].im=0.; 	/*  1. z^2  	*/
 coeff[1].re=3.; coeff[1].im=0.; 	/* +3. z    	*/
 coeff[2].re=2.; coeff[2].im=0.; 	/* +2      	*/
 ndeg[0]=2;  /* since we have a quadratic		*/

/* Now we can call the SLATEC function! 		*/

 cpqr79(ndeg, coeff, root, ierr, work);

 puts("\n");    /* Now print out the result.		*/
 for (i=0;i<ndeg[0];i++ ) printf("(%g,%g).",root[i].re,root[i].im);
 if (ierr[0]) printf("Error Flag = %d\n",ierr[0]);
 puts("\n"); return 0;			   /*  the end	*/
} /* Try compiling with cc simpleCPQ.c -lm -lslatec -lxlf90 */