Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/main/interpoly
Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/main/interpoly
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras |
Filename: | Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/main/interpoly |
Read OK: | ✔ |
File size: | 0266 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* Calculate the coefficients of an integral polynomial using Newton's method of repeated differences */ /* Alter this by hand - a polynomial of degree < 8 */ f(x) { return ((1-x)*(1+x)); } main() { max = 8; c = newvector(max); for (i = 0; i < max; i++) c[i] = f(i); // get values of f at 0, 1, ... for (i = 1; i < max; i++) for (j = max-1; j >= i; j--) { c[j] -= c[j-1]; // get repeated differences c[j] /= i; } for (i = max-2; i >= 0; i--) for (j = i; j < max-1; j++) c[j] -= i*c[j+1]; // get coefficients print(poly2str(c,"x"),"\n"); }
00000000 2f 2a 20 43 61 6c 63 75 6c 61 74 65 20 74 68 65 |/* Calculate the| 00000010 20 63 6f 65 66 66 69 63 69 65 6e 74 73 20 6f 66 | coefficients of| 00000020 20 61 6e 0a 20 20 20 69 6e 74 65 67 72 61 6c 20 | an. integral | 00000030 70 6f 6c 79 6e 6f 6d 69 61 6c 20 75 73 69 6e 67 |polynomial using| 00000040 20 4e 65 77 74 6f 6e 27 73 0a 20 20 20 6d 65 74 | Newton's. met| 00000050 68 6f 64 20 6f 66 20 72 65 70 65 61 74 65 64 20 |hod of repeated | 00000060 64 69 66 66 65 72 65 6e 63 65 73 20 2a 2f 0a 0a |differences */..| 00000070 2f 2a 20 41 6c 74 65 72 20 74 68 69 73 20 62 79 |/* Alter this by| 00000080 20 68 61 6e 64 20 2d 20 61 20 70 6f 6c 79 6e 6f | hand - a polyno| 00000090 6d 69 61 6c 0a 20 20 20 6f 66 20 64 65 67 72 65 |mial. of degre| 000000a0 65 20 3c 20 38 20 2a 2f 0a 66 28 78 29 0a 7b 20 |e < 8 */.f(x).{ | 000000b0 72 65 74 75 72 6e 20 28 28 31 2d 78 29 2a 28 31 |return ((1-x)*(1| 000000c0 2b 78 29 29 3b 20 7d 0a 0a 6d 61 69 6e 28 29 0a |+x)); }..main().| 000000d0 7b 0a 20 6d 61 78 20 3d 20 38 3b 0a 20 63 20 3d |{. max = 8;. c =| 000000e0 20 6e 65 77 76 65 63 74 6f 72 28 6d 61 78 29 3b | newvector(max);| 000000f0 0a 20 66 6f 72 20 28 69 20 3d 20 30 3b 20 69 20 |. for (i = 0; i | 00000100 3c 20 6d 61 78 3b 20 69 2b 2b 29 0a 20 20 63 5b |< max; i++). c[| 00000110 69 5d 20 3d 20 66 28 69 29 3b 20 20 20 20 20 20 |i] = f(i); | 00000120 20 20 20 20 20 20 20 20 20 20 2f 2f 20 67 65 74 | // get| 00000130 20 76 61 6c 75 65 73 20 6f 66 20 66 20 61 74 20 | values of f at | 00000140 30 2c 20 31 2c 20 2e 2e 2e 0a 20 66 6f 72 20 28 |0, 1, .... for (| 00000150 69 20 3d 20 31 3b 20 69 20 3c 20 6d 61 78 3b 20 |i = 1; i < max; | 00000160 69 2b 2b 29 0a 20 20 66 6f 72 20 28 6a 20 3d 20 |i++). for (j = | 00000170 6d 61 78 2d 31 3b 20 6a 20 3e 3d 20 69 3b 20 6a |max-1; j >= i; j| 00000180 2d 2d 29 0a 20 20 20 20 7b 0a 20 20 20 20 20 63 |--). {. c| 00000190 5b 6a 5d 20 2d 3d 20 63 5b 6a 2d 31 5d 3b 20 20 |[j] -= c[j-1]; | 000001a0 20 20 20 20 20 20 20 2f 2f 20 67 65 74 20 72 65 | // get re| 000001b0 70 65 61 74 65 64 20 64 69 66 66 65 72 65 6e 63 |peated differenc| 000001c0 65 73 0a 20 20 20 20 20 63 5b 6a 5d 20 2f 3d 20 |es. c[j] /= | 000001d0 69 3b 0a 20 20 20 20 7d 0a 20 66 6f 72 20 28 69 |i;. }. for (i| 000001e0 20 3d 20 6d 61 78 2d 32 3b 20 69 20 3e 3d 20 30 | = max-2; i >= 0| 000001f0 3b 20 69 2d 2d 29 0a 20 20 66 6f 72 20 28 6a 20 |; i--). for (j | 00000200 3d 20 69 3b 20 6a 20 3c 20 6d 61 78 2d 31 3b 20 |= i; j < max-1; | 00000210 6a 2b 2b 29 0a 20 20 20 20 63 5b 6a 5d 20 2d 3d |j++). c[j] -=| 00000220 20 69 2a 63 5b 6a 2b 31 5d 3b 20 20 20 20 20 20 | i*c[j+1]; | 00000230 20 20 2f 2f 20 67 65 74 20 63 6f 65 66 66 69 63 | // get coeffic| 00000240 69 65 6e 74 73 0a 20 70 72 69 6e 74 28 70 6f 6c |ients. print(pol| 00000250 79 32 73 74 72 28 63 2c 22 78 22 29 2c 22 5c 6e |y2str(c,"x"),"\n| 00000260 22 29 3b 0a 7d 0a |");.}.| 00000266