'***************************************************** '* This program evaluates a polynomial P(x) at x * '* ------------------------------------------------- * '* Ref.: "Mathematiques en Turbo-Pascal By M. Ducamp * '* and A. Reverchon (vol 2), Eyrolles, Paris, 1988" * '* [BIBLI 05]. * '* ------------------------------------------------- * '* SAMPLE RUN: * '* * '* Enter polynomial P(x): x3 - 5x2 + 7x + 4 * '* * '* + X3 - 5 X2 + 7 X + 4 * '* * '* X = 1 * '* P(X) = + 7 * '* X = 10 * '* P(X) = + 574 * '* X = -5/2 * '* P(X) = - 483 / 8 * '* X = 1/3 * '* P(X) = + 157 / 27 * '* X = 0 * '* P(X) = + 4 * '* * '* BASIC version by J-P Moreau * '* (uses file polynoms.bas). * '* (www.jpmoreau.fr) * '***************************************************** defdbl a-h,o-z defint i-n MAXINT = 32767 'Maximum integer number MAXPOL = 20 'Maximum degree for a polynomial SMALL = 1e-20 'small real number ' number zz (real, integer or fractional) ' isrzz=1: zz is real (double precision) ' isrzz=0: zz is integer or fractional ' zzv: value of zz if real ' ipzz: integer value of zz if integer (or numerator value if fractional) ' iqzz: denominator value if fractional (=1 if integer) 'a polynomial P is defined by: 'integer ipdeg (degree of polynomial) 'number cp(MAXPOL) (coefficients of polynomial, double, integer or fractional) 'predefine 3 polynomials P,Q,R (here Q and R are not used) DIM isrcp(MAXPOL),cpv(MAXPOL),ipcp(MAXPOL),iqcp(MAXPOL) DIM isrcq(MAXPOL),cqv(MAXPOL),ipcq(MAXPOL),iqcq(MAXPOL) DIM isrcr(MAXPOL),crv(MAXPOL),ipcr(MAXPOL),iqcr(MAXPOL) cls print tx$=" Enter polynomial P(x): " 'prompting message gosub 4000 'analyse polynomial of text ch$ given if IERROR<>0 then print " Error in polynomial P(x)..." else gosub 5000 'display polynomial P(x) end if 'Enter number x (real,integer or fractional) 10 print input " Enter x value (0 to stop): ",ch$: gosub 1000 'zz=SetNumber(ch$) gosub 6000 'y=P(zz) if IERROR<>0 then print " Error in evaluating polynomial P(x)..." else isrzz=isry:zzv=yv:ipzz=ipy:iqzz=iqy 'zz=y print print " P(x)= ";: gosub 2000: print 'print zz end if if ch$<>"0" then goto 10 END $INCLUDE "Numeric\Polynoms\Polynoms.bas" 'end of file Evalpol.bas