home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!engcon!ropella
- From: ropella@engcon.marshall.ltv.com (GEROPELLA)
- Newsgroups: comp.lang.fortran
- Subject: Permutation through recursion.
- Message-ID: <998@engcon.marshall.ltv.com>
- Date: 4 Sep 92 18:57:56 GMT
- Reply-To: ropella@engcon.UUCP (GEROPELLA)
- Organization: LTV MEG, Dallas, TX
- Lines: 65
-
-
- The following is a VAX fortran polynomial evaluator. But,
- it only works for up to 3 variables. What I would like from
- ya'll is an algorithm that will evaluate any polynomial in
- any number of dimensions for any order. I feel that recursion
- is the only answer and, of course, VAX fortran doesn't have
- recursion built in; but I'm really going to implement it on
- a DEC station, anyway, and DEC fortran does have recursion.
-
- If somebody could tell me how to modify this, or if you have
- a better way of doing it (in fortran, though); please post
- the algorithm. (Since our company was just bought, I'm
- afraid our email is getting screwed up.) Or try to email
- me.
-
-
- CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
- C...
- REAL*4 FUNCTION Poly(X,Eqn,var,order)
- IMPLICIT NONE
- REAL*4 X(4),TFLYOUT,mult,Eqn(*)
- INTEGER var,order,i,j,k,l,numcoef,p,ndx(4)
-
- TFLYOUT = 0.0
- numcoef = 0
- mult =1.0
-
- C The following loop creates the alpha-index in this order:
- C 000,001,002,010,011,020,100,101,110,200
- C where the first digit represents the power of the x variable,
- C the second represents the power of the y variable, and the third
- C represents the power of the z variable in the terms of the polynomial.
-
- do i=0,order
- ndx(1) = i
- do j=0,order-i
- ndx(2) = j
- do k=0,order-i-j
- ndx(3) = k
- mult = 1.0
- numcoef=numcoef+1
- do l=1,var
- if ((x(l) .eq. 0.0) .and. (ndx(l) .eq. 0)) then
- continue
- else
- mult=mult*(X(l)**ndx(l))
- end if
- end do
- c write(*,*) (ndx(p),p=1,3)
- c write(*,*) tflyout,' + ',Eqn(numcoef),' * ',mult
- TFLYOUT=TFLYOUT+Eqn(numcoef)*mult
- end do
- end do
- end do
-
- Poly = TFLYOUT
-
- RETURN
- END
-
-
- glen e. ropella
- ropella@engcon.marshall.ltv.com
- ropella@engcon.uucp
-
-