home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!wupost!waikato.ac.nz!comp.vuw.ac.nz!windy!lhn!mdlcpgs
- Newsgroups: comp.lang.fortran
- Subject: Re: Permutation through recursion.
- Message-ID: <1992Sep8.134515.8196@lhn.gns.cri.nz>
- From: mdlcpgs@lhn.gns.cri.nz (Phil Scadden)
- Date: 8 Sep 92 13:45:15 +1200
- References: <998@engcon.marshall.ltv.com>
- Organization: Institute of Geological and Nuclear Sciences, Lower Hutt, New Zealand
- Lines: 66
-
- In article <998@engcon.marshall.ltv.com>, ropella@engcon.marshall.ltv.com (GEROPELLA) writes:
- >
- > 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
- >
-