home *** CD-ROM | disk | FTP | other *** search
- simsec(a,b,x,y,tol,numrt)
-
- /*given two second-order simultaneous equations in two variables,*/
- /*converts to fourth-order equation and solves for both variables*/
- /*equations of the form */
- /*a(1)*x**2 + a(2)*x*y + a(3)*y**2 + a(4)*x + a(5)*y + a(6) = 0 */
- /*b(1)*x**2 + b(2)*x*y + b(3)*y**2 + b(4)*x + b(5)*y + b(6) = 0 */
-
- int *numrt;
- float a[],b[],x[],y[],tol;
-
- {
- int i,iroot,j,jj,k,kk,l,n,nortx,norty,nroot;
- float c[5],d[5],w1[6],w2[6],rt[12],root[12],zero;
- float dum1[2],dum2[2],dum3[2],dum4[2],c3sqd,c4sqd;
- extern double fabs();
-
-
- zero = tol/10.;
- if((fabs(a[0]) - zero) > 0.)
- {
- if((fabs(b[0]) - zero) >0) goto nq;
- for( i = 0; i <= 5; i++)
- {
- w1[i] = b[i];
- w2[i] = a[i];
- }
- }
- else
- for(i = 0; i <= 5; i++)
- {
- w1[i] = a[i];
- w2[i] = b[i];
- }
-
- if((fabs(w1[1]) - zero) <= 0. && (fabs(w1[3]) - zero) <= 0.)
- {
- d[0] = w1[2];
- d[1] = w1[4];
- d[2] = w1[5];
- quadrt(d,dum1,dum2,tol,&norty);
- rt[0] = dum1[0];
- rt[1] = dum1[1];
- rt[2] = dum2[0];
- rt[3] = dum2[1];
- goto l25;
- }
- c[0] = w1[2];
- c[1] = w1[4];
- c[2] = w1[5];
- c[3] = -w1[1];
- c[4] = -w1[3];
- goto l12;
-
- nq: for(i = 0; i <= 5; i++)
- {
- w1[i] = a[i];
- w2[i] = b[i];
- }
-
- for(i = 0; i <= 1; i++)
- {
- j = (2*(i+1));
- c[i] = w2[0]*w1[j]-w1[0]*w2[j];
- j --;
- c[i+3] = w1[0]*w2[j]-w2[0]*w1[j];
- }
- c[2] = w2[0]*w1[5] - w1[0]*w2[5];
- l12: c3sqd = c[3]*c[3];
- c4sqd = c[4]*c[4];
- d[0] = w2[0]*c[0]*c[0] + w2[1]*c[0]*c[3] + w2[2]*c3sqd;
-
- d[1] = 2.*w2[0]*c[0]*c[1] + w2[1]*(c[0]*c[4] + c[1]*c[3]) + 2.*
- w2[2]*c[3]*c[4] + w2[3]*c[0]*c[3] + w2[4]*c3sqd;
-
- d[2] = w2[0]*(2.*c[0]*c[2]+c[1]*c[1])+w2[1]*(c[1]*c[4]+c[2]*
- c[3]) + w2[2]*c4sqd + w2[3]*(c[0]*c[4] + c[1]*c[3]) + 2.
- *w2[4]*c[3]*c[4] + w2[5]*c3sqd;
-
- d[3] = 2.*w2[0]*c[1]*c[2] + w2[1]*c[2]*c[4] + w2[3]*
- (c[1]*c[4] + c[2]*c[3]) + w2[4]*c4sqd + 2.*w2[5]*c[3]*c[4];
-
- d[4] = w2[0]*c[2]*c[2] + w2[3]*c[2]*c[4] + w2[5]*c4sqd;
-
- biquad(d,dum1,dum2,dum3,dum4,tol,&nroot);
- rt[0] = dum1[0];
- rt[1] = dum1[1];
- rt[2] = dum2[0];
- rt[3] = dum2[1];
- rt[4] = dum3[0];
- rt[5] = dum3[1];
- rt[6] = dum4[0];
- rt[7] = dum4[1];
- *numrt = nroot;
-
- l25: if((*numrt - 1) < 0) return;
- k = 0;
- n = *numrt;
- for(i = 1; i <= n; i++)
- {
- kk = (2 * i) -1;
- if((fabs(rt[kk]) - zero) <= 0.)
- {
- rt[k] = rt[kk - 1];
- k++;
- }
- }
-
- if((k - 1) < 0)
- {
- *numrt = 0;
- return;
- }
- if((k - 1) > 0)
- {
- norty = 0;
- kk = k - 2;
- for(i = 0; i <= kk; i++)
- {
- for(j = i+1; j <= k-1; j++)
- {
- if((fabs(rt[i]-rt[j])-zero) <= 0.) goto l15;
- }
- norty = norty + 1;
- rt[norty-1] = rt[i];
- l15: ;
- }
- norty = norty + 1;
- rt[norty-1] = rt[k-1];
- }
- else norty = 1;
- nortx = 0;
-
- for(j = 0; j <= norty-1; j++)
- {
- k = 0;
- for(i = 0; i <= 6; i += 6)
- {
- if(i == 0)
- {
- c[0] = w1[0];
- c[1] = w1[1] *rt[j] + w1[3];
- c[2] = w1[2] * rt[j]*rt[j] + w1[4]*rt[j]+w1[5];
- }
- else
- {
- c[0] = w2[0];
- c[1] = w2[1] *rt[j] + w2[3];
- c[2] = w2[2] * rt[j]*rt[j] + w2[4]*rt[j]+w2[5];
- }
- quadrt(c,dum1,dum2,tol,&iroot);
- root[k] = dum1[0];
- root[k+1] = dum1[1];
- root[k+2] = dum2[0];
- root[k+3] = dum2[1];
-
- if(i == 0)
- {
- *numrt = iroot;
- k = k + iroot*2;
- }
- }
- if(*numrt <= 0 )
- {
- rt[j] = 99999.;
- goto l27;
- }
- if(iroot <= 0 )
- {
- rt[j] = 99999.;
- goto l27;
- }
- jj = *numrt * 2;
- l = jj + 2;
- kk = (iroot + *numrt) * 2;
-
- for(i = 1; i <= jj-1; i+=2)
- {
- for(k = l-1; k <= kk-1; k+=2)
- {
- if((fabs(root[k]) - zero) <= 0.)
-
- {
- if((fabs(root[i]) - zero) > 0.) goto l30;
- if((fabs(root[k-1] - root[i-1]) - zero) <= 0.) goto l34;
- }
- }
- goto l30;
- l34: nortx = nortx + 1;
- x[nortx - 1] = root[k - 1];
- goto l27;
- l30: ;
- }
- rt[j] = 99999.;
- l27: ;
- }
- *numrt = 0;
- for(i = 0; i <= norty-1; i++)
- {
- if((rt[i] - 99999.) != 0.)
- {
- *numrt = *numrt + 1;
- y[*numrt-1] = rt[i];
- }
- }
- return;
- }