home *** CD-ROM | disk | FTP | other *** search
- biquad(a,r1,r2,r3,r4,tol,numrt)
-
- /*solves fourth order equations of the form */
- /*a(1)x**4 + a(2)x**3 + a(3)x**2 + a(4)x + a(5) = 0 */
- /*for real and/or imaginary roots. */
-
- int *numrt;
- float a[],r1[],r2[],r3[],r4[],tol;
-
- {
- int i,n;
- float xcoefs[4],ycoefs[4],yroots[6],zero;
- float aa,b,c,d,e,f,y;
- extern double fabs(),sqrt();
-
- zero = tol/10.;
- if ((fabs(a[0]) - zero) <= 0.)
- {
- for(i = 0; i <= 3; i++)
- xcoefs[i] = a[i + 1];
- cubic (xcoefs,r1,r2,r3,tol,&n);
- *numrt = n;
- return;
- }
- *numrt = 4;
- for(i = 0; i <= 3; i++)
- xcoefs[i] = a[i + 1]/a[0];
-
- ycoefs[0] = 1.0;
- ycoefs[1] = -xcoefs[1];
- ycoefs[2] = xcoefs[0]*xcoefs[2] - 4.0*xcoefs[3];
- ycoefs[3] = 4.0*xcoefs[1]*xcoefs[3]-xcoefs[0]*xcoefs[0]*xcoefs[3];
- ycoefs[3] = ycoefs[3] - xcoefs[2]*xcoefs[2];
-
- cubic(ycoefs,r1,r2,r3,tol,&n);
-
- yroots[0] = r1[0];
- yroots[1] = r1[1];
- yroots[2] = r2[0];
- yroots[3] = r2[1];
- yroots[4] = r3[0];
- yroots[5] = r3[1];
-
- y = 0.0;
- for(i = 1; i <= 5; i+=2)
- {
- if((fabs(yroots[i]) - zero) <= 0.)
- {
- if((y - yroots[i-1]) <0.)
- y = yroots[i - 1];
- }
- }
- aa = xcoefs[0] * xcoefs[0]*0.25 - xcoefs[1] + y;
- c = -xcoefs[3] + y*y*0.25;
- if((fabs(aa) - zero) <= 0.)
- {
- e = 0.0;
- if((fabs(c) - zero) <= 0.)
- {
- f = 0.0;
- goto r10;
- }
- if(c < 0.) goto r20;
- f = sqrt(c);
- goto r10;
- }
- if(aa < 0.) goto r20;
- e = sqrt(aa);
- b = -xcoefs[2] + 0.5 * xcoefs[0] * y;
- f = b/e*0.5;
-
- r10: ycoefs[0] = 1.0;
- ycoefs[1] = xcoefs[0]*0.5 - e;
- ycoefs[2] = y*0.5 - f;
- quadrt(ycoefs,r1,r2,tol,&n);
- ycoefs[0] = 1.0;
- ycoefs[1] = xcoefs[0]*0.5 + e;
- ycoefs[2] = y*0.5 + f;
- quadrt(ycoefs,r3,r4,tol,&n);
- return;
- r20: *numrt = -*numrt;
- return;
-
-
-
- }