'***************************************************** '* Nth Derivative of a polynomial P(x) * '* ------------------------------------------------- * '* Ref.: "Mathematiques en Turbo-Pascal By M. Ducamp * '* and A. Reverchon (vol 2), Eyrolles, Paris, 1988" * '* [BIBLI 05]. * '* ------------------------------------------------- * '* SAMPLE RUN: * '* * '* Nth DERIVATIVE OF A POLYNOMIAL: * '* * '* P(X) = 4x5 -3/5x3 + x2 -7/2x +11 * '* Order of derivative: 1 * '* * '* * '* 20 X4 - 9 / 5 X2 + 2 X - 7 / 2 * '* * '* * '* Nth DERIVATIVE OF A POLYNOMIAL: * '* * '* P(X) = 4x5 -3/5x3 + x2 -7/2x +11 * '* Order of derivative: 3 * '* * '* * '* 240 X2 - 18 / 5 * '* * '* * '* BASIC version by J-P Moreau. * '* (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, real, integer or fractional) 'predefine 2 polynomials P,R DIM isrcp(MAXPOL),cpv(MAXPOL),ipcp(MAXPOL),iqcp(MAXPOL) DIM isrcr(MAXPOL),crv(MAXPOL),ipcr(MAXPOL),iqcr(MAXPOL) cls print print " Nth DERIVATIVE OF A POLYNOMIAL:" print tx\$=" P(x) = ": gosub 4000 'Enter P(x) print input " Order of derivative: ", n print gosub 500 'call Derivative(P,n,R) if IERROR<>0 then print " Error in calculating derivative." else 'copy R(x) in P(x) for printing ipdeg=irdeg for i=0 to ipdeg isrcp(i)=isrcr(i):cpv(i)=crv(i):ipcp(i)=ipcr(i):iqcp(i)=iqcr(i) next i gosub 5000 'Display P(x) end if END 'Nth derivative of a polynomial P(x) 'DerivPolynom(P,n,R) 'NUMBER: u 500 IERROR=1 irdeg=ipdeg-n if irdeg<0 then irdeg=0 isrcr(0)=0:crv(0)=0#:ipcr(0)=0:iqcr(0)=1 else for ii=0 to irdeg 'R coeff(ii)=P coeff(ii+n) isrcr(ii)=isrcp(ii+n):crv(ii)=cpv(ii+n) ipcr(ii)=ipcp(ii+n):iqcr(ii)=iqcp(ii+n) for jj=1 to n isru=0:uv=ii+jj:ipu=ii+jj:iqu=1 'u=ii+jj 'MultNumber(R coeff(ii), u, R coeff(ii)) isrxx=isrcr(ii):xxv=crv(ii):ipxx=ipcr(ii):iqxx=iqcr(ii) 'xx=cr(ii) isryy=isru:yyv=uv:ipyy=ipu:iqyy=iqu 'yy=u gosub 3100 'zz=xx*yy isrcr(ii)=isrzz:crv(ii)=zzv:ipcr(ii)=ipzz:iqcr(ii)=iqzz 'cr(ii)=zz next jj next ii end if IERROR=0 return \$INCLUDE "numeric\polynoms\polynoms.bas" 'end of file derivpol.bas