DECLARE SUB CHorner (AR#(), AI#(), N%, X0#(), YR#, YI#) DECLARE SUB ZMult (z1#(), z2#(), Z#()) '************************************************************************* '* EVALUATE A COMPLEX POLYNOMIAL BY HORNER'S METHOD * '* --------------------------------------------------------------------- * '* SAMPLE RUN: * '* * '* EVALUATE A CPMPLEX POLYNOMIAL BY HORNER'S METHOD * '* * '* Example: P(Z) = (1+i) Z^4 + (2-i) Z^3 +(3+0.5i) Z^2 + (4-2i) Z * '* + (5-0.75i) * '* * '* For Z = ( 1.5 , 2 ) * '* * '* P(Z) = (-28.9375 ,-6.9375 ) * '* * '* * '* Basic Release 1.0 By J-P Moreau, Paris * '* (www.jpmoreau.fr) * '************************************************************************* DEFDBL A-H, O-Z DEFINT I-N OPTION BASE 0 NMAX = 25 DIM AR(NMAX), AI(NMAX), RR(NMAX), RI(NMAX) DIM Z(2) 'double Y0R, Y0I 'integer N N = 4 ' ORDER OF POLYNOMIAL ' define complex coefficients AR(4) = 1!: AI(4) = 1! ' power 4 AR(3) = 2!: AI(3) = -1! ' power 3 AR(2) = 3!: AI(2) = .5 ' power 2 AR(1) = 4!: AI(1) = -2! ' power 1 AR(0) = 5!: AI(0) = -.75 ' power 0 Z(0) = 1.5 ' complex argument Z(1) = 2! CLS PRINT PRINT " EVALUATE A COMPLEX POLYNOMIAL BY HORNER'S METHOD" PRINT CHorner AR(), AI(), N, Z(), Y0R, Y0I PRINT " For Z = ("; Z(0); ","; Z(1); ")" PRINT " P(Z) = ("; Y0R; ","; Y0I; ")" END SUB CHorner (AR(), AI(), N, X0(), YR, YI) DIM tmp(2), tmp0(2) YR = AR(N): YI = AI(N) FOR i = N - 1 TO 0 STEP -1 tmp0(0) = YR: tmp0(1) = YI ZMult tmp0(), X0(), tmp() YR = tmp(0) + AR(i) YI = tmp(1) + AI(i) NEXT i END SUB ' multiply two complex numbers SUB ZMult (z1(), z2(), Z()) Z(0) = (z1(0) * z2(0)) - (z1(1) * z2(1)) Z(1) = (z1(0) * z2(1)) + (z1(1) * z2(0)) END SUB