1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
|
\begin{page}{manpageXXc02}{NAG On-line Documentation: c02}
\beginscroll
\begin{verbatim}
C02(3NAG) Foundation Library (12/10/92) C02(3NAG)
C02 -- Zeros of Polynomials Introduction -- C02
Chapter C02
Zeros of Polynomials
1. Scope of the Chapter
This chapter is concerned with computing the zeros of a
polynomial with real or complex coefficients.
2. Background to the Problems
Let f(z) be a polynomial of degree n with complex coefficients
a :
i
n n-1 n-2
f(z)==a z +a z +a z +...+a z+a , a /=0.
0 1 2 n-1 n 0
A complex number z is called a zero of f(z) (or equivalently a
1
root of the equation f(z)=0), if:
f(z )=0.
1
If z is a zero, then f(z) can be divided by a factor (z-z ):
1 1
f(z)=(z-z )f (z) (1)
1 1
where f (z) is a polynomial of degree n-1. By the Fundamental
1
Theorem of Algebra, a polynomial f(z) always has a zero, and so
the process of dividing out factors (z-z ) can be continued until
i
we have a complete factorization of f(z)
f(z)==a (z-z )(z-z )...(z-z ).
0 1 2 n
Here the complex numbers z ,z ,...,z are the zeros of f(z); they
1 2 n
may not all be distinct, so it is sometimes more convenient to
write:
m m m
1 2 k
f(z)==a (z-z ) (z-z ) ...(z-z ) , k<=n,
0 1 2 k
with distinct zeros z ,z ,...,z and multiplicities m >=1. If
1 2 k i
m =1, z is called a single zero, if m >1, z is called a
i i i i
multiple or repeated zero; a multiple zero is also a zero of the
derivative of f(z).
If the coefficients of f(z) are all real, then the zeros of f(z)
are either real or else occur as pairs of conjugate complex
numbers x+iy and x-iy. A pair of complex conjugate zeros are the
2
zeros of a quadratic factor of f(z), (z +rz+s), with real
coefficients r and s.
Mathematicians are accustomed to thinking of polynomials as
pleasantly simple functions to work with. However the problem of
numerically computing the zeros of an arbitrary polynomial is far
from simple. A great variety of algorithms have been proposed, of
which a number have been widely used in practice; for a fairly
comprehensive survey, see Householder [1]. All general algorithms
are iterative. Most converge to one zero at a time; the
corresponding factor can then be divided out as in equation (1)
above - this process is called deflation or, loosely, dividing
out the zero - and the algorithm can be applied again to the
polynomial f (z). A pair of complex conjugate zeros can be
1
divided out together - this corresponds to dividing f(z) by a
quadratic factor.
Whatever the theoretical basis of the algorithm, a number of
practical problems arise: for a thorough discussion of some of
them see Peters and Wilkinson [2] and Wilkinson [3]. The most
elementary point is that, even if z is mathematically an exact
1
zero of f(z), because of the fundamental limitations of computer
arithmetic the computed value of f(z ) will not necessarily be
1
exactly 0.0. In practice there is usually a small region of
values of z about the exact zero at which the computed value of
f(z) becomes swamped by rounding errors. Moreover in many
algorithms this inaccuracy in the computed value of f(z) results
in a similar inaccuracy in the computed step from one iterate to
the next. This limits the precision with which any zero can be
computed. Deflation is another potential cause of trouble, since,
in the notation of equation (1), the computed coefficients of
f (z) will not be completely accurate, especially if z is not an
1 1
exact zero of f(z); so the zeros of the computed f (z) will
1
deviate from the zeros of f(z).
A zero is called ill-conditioned if it is sensitive to small
changes in the coefficients of the polynomial. An ill-conditioned
zero is likewise sensitive to the computational inaccuracies just
mentioned. Conversely a zero is called well-conditioned if it is
comparatively insensitive to such perturbations. Roughly speaking
a zero which is well separated from other zeros is well-
conditioned, while zeros which are close together are ill-
conditioned, but in talking about 'closeness' the decisive factor
is not the absolute distance between neighbouring zeros but their
ratio: if the ratio is close to 1 the zeros are ill-conditioned.
In particular, multiple zeros are ill-conditioned. A multiple
zero is usually split into a cluster of zeros by perturbations in
the polynomial or computational inaccuracies.
2.1. References
[1] Householder A S (1970) The Numerical Treatment of a Single
Nonlinear Equation. McGraw-Hill.
[2] Peters G and Wilkinson J H (1971) Practical Problems Arising
in the Solution of Polynomial Equations. J. Inst. Maths
Applics. 8 16--35.
[3] Wilkinson J H (1963) Rounding Errors in Algebraic Processes,
Chapter 2. HMSO.
3. Recommendations on Choice and Use of Routines
3.1. Discussion
Two routines are available: C02AFF for polynomials with complex
coefficients and C02AGF for polynomials with real coefficients.
C02AFF and C02AGF both use a variant of Laguerre's Method due to
BT Smith to calculate each zero until the degree of the deflated
polynomial is less than 3, whereupon the remaining zeros are
obtained using the 'standard' closed formulae for a quadratic or
linear equation.
The accuracy of the roots will depend on how ill-conditioned they
are. Peters and Wilkinson [2] describe techniques for estimating
the errors in the zeros after they have been computed.
3.2. Index
Zeros of a complex polynomial C02AFF
Zeros of a real polynomial C02AGF
C02 -- Zeros of Polynomials Contents -- C02
Chapter C02
Zeros of Polynomials
C02AFF All zeros of complex polynomial, modified Laguerre method
C02AGF All zeros of real polynomial, modified Laguerre method
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc02aff}{NAG On-line Documentation: c02aff}
\beginscroll
\begin{verbatim}
C02AFF(3NAG) Foundation Library (12/10/92) C02AFF(3NAG)
C02 -- Zeros of Polynomials C02AFF
C02AFF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C02AFF finds all the roots of a complex polynomial equation,
using a variant of Laguerre's Method.
2. Specification
SUBROUTINE C02AFF (A, N, SCALE, Z, W, IFAIL)
INTEGER N, IFAIL
DOUBLE PRECISION A(2,N+1), Z(2,N), W(4*(N+1))
LOGICAL SCALE
3. Description
The routine attempts to find all the roots of the nth degree
complex polynomial equation
n n-1 n-2
P(z)=a z +a z +a z +...+a z+a =0.
0 1 2 n-1 n
The roots are located using a modified form of Laguerre's Method,
originally proposed by Smith [2].
The method of Laguerre [3] can be described by the iterative
scheme
-n*P(z )
k
L(z )=z -z = ----------------,
k k+1 k
P'(z )+- /H(z )
k \/ k
2
where H(z )=(n-1)*[(n-1)*(P'(z )) -n*P(z )P''(z )], and z is
k k k k 0
specified.
The sign in the denominator is chosen so that the modulus of the
Laguerre step at z , viz. |L(z )|, is as small as possible. The
k k
method can be shown to be cubically convergent for isolated roots
(real or complex) and linearly convergent for multiple roots.
The routine generates a sequence of iterates z , z , z ,..., such
1 2 3
that |P(z )|<|P(z )| and ensures that z +L(z ) 'roughly'
k+1 k k+1 k+1
lies inside a circular region of radius |F| about z known to
k
contain a zero of P(z); that is, |L(z )|<=|F|, where F denotes
k+1
the Fejer bound (see Marden [1]) at the point z . Following Smith
k
[2], F is taken to be min(B,1.445*n*R), where B is an upper bound
for the magnitude of the smallest zero given by
1/n
B=1.0001*min(\/n*L(z ),|r |,|a /a | ),
k 1 n 0
r is the zero X of smaller magnitude of the quadratic equation
1
2
2(P''(z )/(2*n*(n-1)))X +2(P'(z )/n)X+P(z )=0
k k k
and the Cauchy lower bound R for the smallest zero is computed
(using Newton's Method) as the positive root of the polynomial
equation
n n-1 n-2
|a |z +|a |z +|a |z +...+|a |z-|a |=0.
0 1 2 n-1 n
Starting from the origin, successive iterates are generated
according to the rule z =z +L(z ) for k = 1,2,3,... and L(z )
k+1 k k k
is 'adjusted' so that |P(z )|<|P(z )| and |L(z )|<=|F|. The
k+1 k k+1
iterative procedure terminates if P(z ) is smaller in absolute
k+1
value than the bound on the rounding error in P(z ) and the
k+1
current iterate z =z is taken to be a zero of P(z). The
p k+1
~
deflated polynomial P(z)=P(z)/(z-z ) of degree n-1 is then
p
formed, and the above procedure is repeated on the deflated
polynomial until n<3, whereupon the remaining roots are obtained
via the 'standard' closed formulae for a linear (n = 1) or
quadratic (n = 2) equation.
To obtain the roots of a quadratic polynomial, C02AHF(*) can be
used.
4. References
[1] Marden M (1966) Geometry of Polynomials. Mathematical
Surveys. 3 Am. Math. Soc., Providence, RI.
[2] Smith B T (1967) ZERPOL: A Zero Finding Algorithm for
Polynomials Using Laguerre's Method. Technical Report.
Department of Computer Science, University of Toronto,
Canada.
[3] Wilkinson J H (1965) The Algebraic Eigenvalue Problem.
Clarendon Press.
5. Parameters
1: A(2,N+1) -- DOUBLE PRECISION array Input
On entry: if A is declared with bounds (2,0:N), then A(1,i)
and A(2,i) must contain the real and imaginary parts of a
i
n-i
(i.e., the coefficient of z ), for i=0,1,...,n.
Constraint: A(1,0) /= 0.0 or A(2,0) /= 0.0.
2: N -- INTEGER Input
On entry: the degree of the polynomial, n. Constraint: N >=
1.
3: SCALE -- LOGICAL Input
On entry: indicates whether or not the polynomial is to be
scaled. See Section 8 for advice on when it may be
preferable to set SCALE = .FALSE. and for a description of
the scaling strategy. Suggested value: SCALE = .TRUE..
4: Z(2,N) -- DOUBLE PRECISION array Output
On exit: the real and imaginary parts of the roots are
stored in Z(1,i) and Z(2,i) respectively, for i=1,2,...,n.
5: W(4*(N+1)) -- DOUBLE PRECISION array Workspace
6: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL= 1
On entry A(1,0) = 0.0 and A(2,0) = 0.0,
or N < 1.
IFAIL= 2
The iterative procedure has failed to converge. This error
is very unlikely to occur. If it does, please contact NAG
immediately, as some basic assumption for the arithmetic has
been violated. See also Section 8.
IFAIL= 3
Either overflow or underflow prevents the evaluation of P(z)
near some of its zeros. This error is very unlikely to
occur. If it does, please contact NAG immediately. See also
Section 8.
7. Accuracy
All roots are evaluated as accurately as possible, but because of
the inherent nature of the problem complete accuracy cannot be
guaranteed.
8. Further Comments
If SCALE = .TRUE., then a scaling factor for the coefficients is
chosen as a power of the base B of the machine so that the
EMAX-P
largest coefficient in magnitude approaches THRESH = B .
Users should note that no scaling is performed if the largest
coefficient in magnitude exceeds THRESH, even if SCALE = .TRUE..
(For definition of B, EMAX and P see the Chapter Introduction
X02.)
However, with SCALE = .TRUE., overflow may be encountered when
the input coefficients a ,a ,a ,...,a vary widely in magnitude,
0 1 2 n
(4*P)
particularly on those machines for which B overflows. In
such cases, SCALE should be set to .FALSE. and the coefficients
scaled so that the largest coefficient in magnitude does not
(EMAX-2*P)
exceed B .
Even so, the scaling strategy used in C02AFF is sometimes
insufficient to avoid overflow and/or underflow conditions. In
such cases, the user is recommended to scale the independent
variable (z) so that the disparity between the largest and
smallest coefficient in magnitude is reduced. That is, use the
routine to locate the zeros of the polynomial d*P(cz) for some
suitable values of c and d. For example, if the original
-100 100 20 -10
polynomial was P(z)=2 i+2 z , then choosing c=2 and
100 20
d=2 , for instance, would yield the scaled polynomial i+z ,
which is well-behaved relative to overflow and underflow and has
10
zeros which are 2 times those of P(z).
If the routine fails with IFAIL = 2 or 3, then the real and
imaginary parts of any roots obtained before the failure occurred
are stored in Z in the reverse order in which they were found.
Let n denote the number of roots found before the failure
R
occurred. Then Z(1,n) and Z(2,n) contain the real and imaginary
parts of the 1st root found, Z(1,n-1) and Z(2,n-1) contain the
real and imaginary parts of the 2nd root found, ..., Z(1,n ) and
R
Z(2,n ) contain the real and imaginary parts of the n th root
R R
found. After the failure has occurred, the remaining 2*(n-n )
R
elements of Z contain a large negative number (equal to
-1/(X02AMF().\/2)).
9. Example
5 4 3 2
To find the roots of the polynomial a z +a z +a z +a z +a z+a =0,
0 1 2 3 4 5
where a =(5.0+6.0i), a =(30.0+20.0i), a =-(0.2+6.0i),
0 1 2
a =(50.0+100000.0i), a =-(2.0-40.0i) and a =(10.0+1.0i).
3 4 5
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc02agf}{NAG On-line Documentation: c02agf}
\beginscroll
\begin{verbatim}
C02AGF(3NAG) Foundation Library (12/10/92) C02AGF(3NAG)
C02 -- Zeros of Polynomials C02AGF
C02AGF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C02AGF finds all the roots of a real polynomial equation, using a
variant of Laguerre's Method.
2. Specification
SUBROUTINE C02AGF (A, N, SCALE, Z, W, IFAIL)
INTEGER N, IFAIL
DOUBLE PRECISION A(N+1), Z(2,N), W(2*(N+1))
LOGICAL SCALE
3. Description
The routine attempts to find all the roots of the nth degree real
polynomial equation
n n-1 n-2
P(z)=a z +a z +a z +...+a z+a =0.
0 1 2 n-1 n
The roots are located using a modified form of Laguerre's Method,
originally proposed by Smith [2].
The method of Laguerre [3] can be described by the iterative
scheme
-n*P(z )
k
L(z )=z -z = ----------------,
k k+1 k
P'(z )+- /H(z )
k \/ k
2
where H(z )=(n-1)*[(n-1)*(P'(z )) -n*P(z )P''(z )], and z is
k k k k 0
specified.
The sign in the denominator is chosen so that the modulus of the
Laguerre step at z , viz. |L(z )|, is as small as possible. The
k k
method can be shown to be cubically convergent for isolated roots
(real or complex) and linearly convergent for multiple roots.
The routine generates a sequence of iterates z , z , z ,..., such
1 2 3
that |P(z +1)|<|P(z )| and ensures that z +L(z ) 'roughly'
k k k+1 k+1
lies inside a circular region of radius |F| about z known to
k
contain a zero of P(z); that is, |L(z )|<=|F|, where F denotes
k+1
the Fejer bound (see Marden [1]) at the point z . Following Smith
k
[2], F is taken to be min(B,1.445*n*R), where B is an upper bound
for the magnitude of the smallest zero given by
1/n
B=1.0001*min(\/n*L(z ),|r |,|a /a | ),
k 1 n 0
r is the zero X of smaller magnitude of the quadratic equation
1
2
2(P''(z )/(2*n*(n-1)))X +2(P'(z )/n)X+P(z )=0
k k k
and the Cauchy lower bound R for the smallest zero is computed
(using Newton's Method) as the positive root of the polynomial
equation
n n-1 n-2
|a |z +|a |z +|a |z +...+|a |z-|a |=0.
0 1 2 n-1 n
Starting from the origin, successive iterates are generated
according to the rule z =z +L(z ) for k=1,2,3,... and L(z ) is
k+1 k k k
k+1 k k+1
iterative procedure terminates if P(z ) is smaller in absolute
k+1
value than the bound on the rounding error in P(z ) and the
k+1
current iterate z =z is taken to be a zero of P(z) (as is its
p k-1
conjugate z if z is complex). The deflated polynomial
p p
~
P(z)=P(z)/(z-z ) of degree n-1 if z is real
p p
~
(P(z)=P(z)/((z-z )(z-z )) of degree n-2 if z is complex) is then
p p p
formed, and the above procedure is repeated on the deflated
polynomial until n<3, whereupon the remaining roots are obtained
via the 'standard' closed formulae for a linear (n = 1) or
quadratic (n = 2) equation.
To obtain the roots of a quadratic polynomial, C02AJF(*) can be
used.
4. References
[1] Marden M (1966) Geometry of Polynomials. Mathematical
Surveys. 3 Am. Math. Soc., Providence, RI.
[2] Smith B T (1967) ZERPOL: A Zero Finding Algorithm for
Polynomials Using Laguerre's Method. Technical Report.
Department of Computer Science, University of Toronto,
Canada.
[3] Wilkinson J H (1965) The Algebraic Eigenvalue Problem.
Clarendon Press.
5. Parameters
1: A(N+1) -- DOUBLE PRECISION array Input
On entry: if A is declared with bounds (0:N), then A(i)
n-i
must contain a (i.e., the coefficient of z ), for
i
i=0,1,...,n. Constraint: A(0) /= 0.0.
2: N -- INTEGER Input
On entry: the degree of the polynomial, n. Constraint: N >=
1.
3: SCALE -- LOGICAL Input
On entry: indicates whether or not the polynomial is to be
scaled. See Section 8 for advice on when it may be
preferable to set SCALE = .FALSE. and for a description of
the scaling strategy. Suggested value: SCALE = .TRUE..
4: Z(2,N) -- DOUBLE PRECISION array Output
On exit: the real and imaginary parts of the roots are
stored in Z(1,i) and Z(2,i) respectively, for i=1,2,...,n.
Complex conjugate pairs of roots are stored in consecutive
pairs of elements of Z; that is, Z(1,i+1) = Z(1,i) and
Z(2,i+1)=-Z(2,i).
5: W(2*(N+1)) -- DOUBLE PRECISION array Workspace
6: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL= 1
On entry A(0) = 0.0,
or N < 1.
IFAIL= 2
The iterative procedure has failed to converge. This error
is very unlikely to occur. If it does, please contact NAG
immediately, as some basic assumption for the arithmetic has
been violated. See also Section 8.
IFAIL= 3
Either overflow or underflow prevents the evaluation of P(z)
near some of its zeros. This error is very unlikely to
occur. If it does, please contact NAG immediately. See also
Section 8.
7. Accuracy
All roots are evaluated as accurately as possible, but because of
the inherent nature of the problem complete accuracy cannot be
guaranteed.
8. Further Comments
If SCALE = .TRUE., then a scaling factor for the coefficients is
chosen as a power of the base B of the machine so that the
EMAX-P
largest coefficient in magnitude approaches THRESH = B .
Users should note that no scaling is performed if the largest
coefficient in magnitude exceeds THRESH, even if SCALE = .TRUE..
(For definition of B, EMAX and P see the Chapter Introduction
X02.)
However, with SCALE = .TRUE., overflow may be encountered when
the input coefficients a ,a ,a ,...,a vary widely in magnitude,
0 1 2 n
(4*P)
particularly on those machines for which B overflows. In
such cases, SCALE should be set to .FALSE. and the coefficients
scaled so that the largest coefficient in magnitude does not
(EMAX-2*P)
exceed B .
Even so, the scaling strategy used in C02AGF is sometimes
insufficient to avoid overflow and/or underflow conditions. In
such cases, the user is recommended to scale the independent
variable (z) so that the disparity between the largest and
smallest coefficient in magnitude is reduced. That is, use the
routine to locate the zeros of the polynomial d*P(cz) for some
suitable values of c and d. For example, if the original
-100 100 20 -10
polynomial was P(z)=2 +2 z , then choosing c=2 and
100 20
d=2 , for instance, would yield the scaled polynomial 1+z ,
which is well-behaved relative to overflow and underflow and has
10
zeros which are 2 times those of P(z).
If the routine fails with IFAIL = 2 or 3, then the real and
imaginary parts of any roots obtained before the failure occurred
are stored in Z in the reverse order in which they were found.
Let n denote the number of roots found before the failure
R
occurred. Then Z(1,n) and Z(2,n) contain the real and imaginary
parts of the 1st root found, Z(1,n-1) and Z(2,n-1) contain the
real and imaginary parts of the 2nd root found, ..., Z(1,n ) and
R
Z(2,n ) contain the real and imaginary parts of the n th root
R R
found. After the failure has occurred, the remaining 2*(n-n )
R
elements of Z contain a large negative number (equal to
-1/(X02AMF().\/2)).
9. Example
To find the roots of the 5th degree polynomial
5 4 3 2
z +2z +3z +4z +5z+6=0.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc05}{NAG On-line Documentation: c05}
\beginscroll
\begin{verbatim}
C05(3NAG) Foundation Library (12/10/92) C05(3NAG)
C05 -- Roots of One or More Transcendental Equations
Introduction -- C05
Chapter C05
Roots of One or More Transcendental Equations
1. Scope of the Chapter
This chapter is concerned with the calculation of real zeros of
continuous real functions of one or more variables. (Complex
equations must be expressed in terms of the equivalent larger
system of real equations.)
2. Background to the Problems
The chapter divides naturally into two parts.
2.1. A Single Equation
The first deals with the real zeros of a real function of a
single variable f(x).
At present, there is only one routine with a simple calling
sequence. This routine assumes that the user can determine an
initial interval [a,b] within which the desired zero lies, that
is f(a)*f(b)<0, and outside which all other zeros lie. The
routine then systematically subdivides the interval to produce a
final interval containing the zero. This final interval has a
length bounded by the user's specified error requirements; the
end of the interval where the function has smallest magnitude is
returned as the zero. This routine is guaranteed to converge to a
simple zero of the function. (Here we define a simple zero as a
zero corresponding to a sign-change of the function.) The
algorithm used is due to Bus and Dekker.
2.2. Systems of Equations
The routines in the second part of this chapter are designed to
solve a set of nonlinear equations in n unknowns
T
f (x)=0, i=1,2,...,n, x=(x ,x ,...,x ) (1)
i 1 2 n
where T stands for transpose.
It is assumed that the functions are continuous and
differentiable so that the matrix of first partial derivatives of
the functions, the Jacobian matrix J (x)=ddf /ddx evaluated at
ij i j
the point x, exists, though it may not be possible to calculate
it directly.
The functions f must be independent, otherwise there will be an
i
infinity of solutions and the methods will fail. However, even
when the functions are independent the solutions may not be
unique. Since the methods are iterative, an initial guess at the
solution has to be supplied, and the solution located will
usually be the one closest to this initial guess.
2.3. References
[1] Gill P E and Murray W (1976) Algorithms for the Solution of
the Nonlinear Least-squares Problem. NAC 71 National
Physical Laboratory.
[2] More J J, Garbow B S and Hillstrom K E (1974) User Guide for
Minpack-1. ANL-80-74 Argonne National Laboratory.
[3] Ortega J M and Rheinboldt W C (1970) Iterative Solution of
Nonlinear Equations in Several Variables. Academic Press.
[4] Rabinowitz P (1970) Numerical Methods for Nonlinear
Algebraic Equations. Gordon and Breach.
3. Recommendations on Choice and Use of Routines
3.1. Zeros of Functions of One Variable
There is only one routine (C05ADF) for solving a single nonlinear
equation. This routine is designed for solving problems where the
function f(x) whose zero is to be calculated, can be coded as a
user-supplied routine.
C05ADF may only be used when the user can supply an interval
[a,b] containing the zero, that is f(a)*f(b)<0.
3.2. Solution of Sets of Nonlinear Equations
The solution of a set of nonlinear equations
f (x ,x ,...,x )=0, i=1,2,...,n (2)
i 1 2 n
can be regarded as a special case of the problem of finding a
minimum of a sum of squares
m
/ 2
s(x)= | [f (x ,x ,...,x )] (m>=n). (3)
/ i 1 2 n
i=1
So the routines in Chapter E04 of the Library are relevant as
well as the special nonlinear equations routines.
There are two routines (C05NBF and C05PBF) for solving a set of
nonlinear equations. These routines require the f (and possibly
i
their derivatives) to be calculated in user-supplied routines.
These should be set up carefully so the Library routines can work
as efficiently as possible.
The main decision which has to be made by the user is whether to
ddf
i
supply the derivatives ----. It is advisable to do so if
ddx
j
possible, since the results obtained by algorithms which use
derivatives are generally more reliable than those obtained by
algorithms which do not use derivatives.
C05PBF requires the user to provide the derivatives, whilst
C05NBF does not. C05NBF and C05PBF are easy-to-use routines. A
routine, C05ZAF, is provided for use in conjunction with C05PBF
to check the user-provided derivatives for consistency with the
functions themselves. The user is strongly advised to make use of
this routine whenever C05PBF is used.
Firstly, the calculation of the functions and their derivatives
should be ordered so that cancellation errors are avoided. This
is particularly important in a routine that uses these quantities
to build up estimates of higher derivatives.
Secondly, scaling of the variables has a considerable effect on
the efficiency of a routine. The problem should be designed so
that the elements of x are of similar magnitude. The same comment
applies to the functions, all the f should be of comparable
i
size.
The accuracy is usually determined by the accuracy parameters of
the routines, but the following points may be useful:
(i) Greater accuracy in the solution may be requested by
choosing smaller input values for the accuracy parameters.
However, if unreasonable accuracy is demanded, rounding
errors may become important and cause a failure.
(ii) Some idea of the accuracies of the x may be obtained by
i
monitoring the progress of the routine to see how many
figures remain unchanged during the last few iterations.
(iii) An approximation to the error in the solution x, given by e
where e is the solution to the set of linear equations
J(x)e=-f(x)
T
where f(x)=(f (x),f (x),...,f (x)) (see Chapter F04).
1 2 n
(iv) If the functions f (x) are changed by small amounts
i
(epsilon) , for i=1,2,...,n, then the corresponding change
i
in the solution x is given approximately by (sigma), where
(sigma) is the solution of the set of linear equations
J(x)(sigma)=-(epsilon), (see Chapter F04).
Thus one can estimate the sensitivity of x to any
uncertainties in the specification of f (x), for
i
i=1,2,...,n.
3.3. Index
Zeros of functions of one variable:
Bus and Dekker algorithm C05ADF
Zeros of functions of several variables:
easy-to-use C05NBF
easy-to-use, derivatives required C05PBF
Checking Routine:
Checks user-supplied Jacobian C05ZAF
C05 -- Roots of One or More Transcendental Equations
Contents -- C05
Chapter C05
Roots of One or More Transcendental Equations
C05ADF Zero of continuous function in given interval, Bus and
Dekker algorithm
C05NBF Solution of system of nonlinear equations using function
values only
C05PBF Solution of system of nonlinear equations using 1st
derivatives
C05ZAF Check user's routine for calculating 1st derivatives
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc05adf}{NAG On-line Documentation: c05adf}
\beginscroll
\begin{verbatim}
C05ADF(3NAG) Foundation Library (12/10/92) C05ADF(3NAG)
C05 -- Roots of One or More Transcendental Equations C05ADF
C05ADF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C05ADF locates a zero of a continuous function in a given
interval by a combination of the methods of linear interpolation,
extrapolation and bisection.
2. Specification
SUBROUTINE C05ADF (A, B, EPS, ETA, F, X, IFAIL)
INTEGER IFAIL
DOUBLE PRECISION A, B, EPS, ETA, F, X
EXTERNAL F
3. Description
The routine attempts to obtain an approximation to a simple zero
of the function f(x) given an initial interval [a,b] such that
f(a)*f(b)<=0. The zero is found by calls to C05AZF(*) whose
specification should be consulted for details of the method used.
The approximation x to the zero (alpha) is determined so that one
or both of the following criteria are satisfied:
(i) |x-(alpha)|<EPS,
(ii) |f(x)|<ETA.
4. References
None.
5. Parameters
1: A -- DOUBLE PRECISION Input
On entry: the lower bound of the interval, a.
2: B -- DOUBLE PRECISION Input
On entry: the upper bound of the interval, b. Constraint: B
/= A.
3: EPS -- DOUBLE PRECISION Input
On entry: the absolute tolerance to which the zero is
required (see Section 3). Constraint: EPS > 0.0.
4: ETA -- DOUBLE PRECISION Input
On entry: a value such that if |f(x)|<ETA, x is accepted as
the zero. ETA may be specified as 0.0 (see Section 7).
5: F -- DOUBLE PRECISION FUNCTION, supplied by the user.
External Procedure
F must evaluate the function f whose zero is to be
determined.
Its specification is:
DOUBLE PRECISION FUNCTION F (XX)
DOUBLE PRECISION XX
1: XX -- DOUBLE PRECISION Input
On entry: the point at which the function must be
evaluated.
F must be declared as EXTERNAL in the (sub)program from
which C05ADF is called. Parameters denoted as Input
must not be changed by this procedure.
6: X -- DOUBLE PRECISION Output
On exit: the approximation to the zero.
7: IFAIL -- INTEGER Input/Output
Before entry, IFAIL must be assigned a value. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
Unless the routine detects an error (see Section 6), IFAIL
contains 0 on exit.
6. Error Indicators and Warnings
Errors detected by the routine:
IFAIL= 1
On entry EPS <= 0.0,
or A = B,
or F(A)*F(B)>0.0.
IFAIL= 2
Too much accuracy has been requested in the computation,
that is, EPS is too small for the computer being used. The
final value of X is an accurate approximation to the zero.
IFAIL= 3
A change in sign of f(x) has been determined as occurring
near the point defined by the final value of X. However,
there is some evidence that this sign-change corresponds to
a pole of f(x).
IFAIL= 4
Indicates that a serious error has occurred in C05AZF(*).
Check all routine calls. Seek expert help.
7. Accuracy
This depends on the value of EPS and ETA. If full machine
accuracy is required, they may be set very small, resulting in an
error exit with IFAIL = 2, although this may involve more
iterations than a lesser accuracy. The user is recommended to set
ETA = 0.0 and to use EPS to control the accuracy, unless he has
considerable knowledge of the size of f(x) for values of x near
the zero.
8. Further Comments
The time taken by the routine depends primarily on the time spent
evaluating F (see Section 5).
If it is important to determine an interval of length less than
EPS containing the zero, or if the function F is expensive to
evaluate and the number of calls to F is to be restricted, then
use of C05AZF(*) is recommended. Use of C05AZF(*) is also
recommended when the structure of the problem to be solved does
not permit a simple function F to be written: the reverse
communication facilities of C05AZF(*) are more flexible than the
direct communication of F required by C05ADF.
9. Example
-x
The example program below calculates the zero of e -x within the
interval [0,1] to approximately 5 decimal places.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc05nbf}{NAG On-line Documentation: c05nbf}
\beginscroll
\begin{verbatim}
C05NBF(3NAG) Foundation Library (12/10/92) C05NBF(3NAG)
C05 -- Roots of One or More Transcendental Equations C05NBF
C05NBF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C05NBF is an easy-to-use routine to find a solution of a system
of nonlinear equations by a modification of the Powell hybrid
method.
2. Specification
SUBROUTINE C05NBF (FCN, N, X, FVEC, XTOL, WA, LWA, IFAIL)
INTEGER N, LWA, IFAIL
DOUBLE PRECISION X(N), FVEC(N), XTOL, WA(LWA)
EXTERNAL FCN
3. Description
The system of equations is defined as:
f (x ,x ,...,x )=0, for i=1,2,...,n.
i 1 2 n
C05NBF is based upon the MINPACK routine HYBRD1 (More et al [1]).
It chooses the correction at each step as a convex combination of
the Newton and scaled gradient directions. Under reasonable
conditions this guarantees global convergence for starting points
far from the solution and a fast rate of convergence. The
Jacobian is updated by the rank-1 method of Broyden. At the
starting point the Jacobian is approximated by forward
differences, but these are not used again until the rank-1 method
fails to produce satisfactory progress. For more details see
Powell [2].
4. References
[1] More J J, Garbow B S and Hillstrom K E User Guide for
MINPACK-1. Technical Report ANL-80-74. Argonne National
Laboratory.
[2] Powell M J D (1970) A Hybrid Method for Nonlinear Algebraic
Equations. Numerical Methods for Nonlinear Algebraic
Equations. (ed P Rabinowitz) Gordon and Breach.
5. Parameters
1: FCN -- SUBROUTINE, supplied by the user.
External Procedure
FCN must return the values of the functions f at a point x.
i
Its specification is:
SUBROUTINE FCN (N, X, FVEC, IFLAG)
INTEGER N, IFLAG
DOUBLE PRECISION X(N), FVEC(N)
1: N -- INTEGER Input
On entry: the number of equations, n.
2: X(N) -- DOUBLE PRECISION array Input
On entry: the components of the point x at which the
functions must be evaluated.
3: FVEC(N) -- DOUBLE PRECISION array Output
On exit: the function values f (x) (unless IFLAG is
i
set to a negative value by FCN).
4: IFLAG -- INTEGER Input/Output
On entry: IFLAG > 0. On exit: in general, IFLAG should
not be reset by FCN. If, however, the user wishes to
terminate execution (perhaps because some illegal point
X has been reached), then IFLAG should be set to a
negative integer. This value will be returned through
IFAIL.
FCN must be declared as EXTERNAL in the (sub)program
from which C05NBF is called. Parameters denoted as
Input must not be changed by this procedure.
2: N -- INTEGER Input
On entry: the number of equations, n. Constraint: N > 0.
3: X(N) -- DOUBLE PRECISION array Input/Output
On entry: an initial guess at the solution vector. On
exit: the final estimate of the solution vector.
4: FVEC(N) -- DOUBLE PRECISION array Output
On exit: the function values at the final point, X.
5: XTOL -- DOUBLE PRECISION Input
On entry: the accuracy in X to which the solution is
required. Suggested value: the square root of the machine
precision. Constraint: XTOL >= 0.0.
6: WA(LWA) -- DOUBLE PRECISION array Workspace
7: LWA -- INTEGER Input
On entry: the dimension of the array WA. Constraint:
LWA>=N*(3*N+13)/2.
8: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL< 0
The user has set IFLAG negative in FCN. The value of IFAIL
will be the same as the user's setting of IFLAG.
IFAIL= 1
On entry N <= 0,
or XTOL < 0.0,
or LWA<N*(3*N+13)/2.
IFAIL= 2
There have been at least 200*(N+1) evaluations of FCN.
Consider restarting the calculation from the final point
held in X.
IFAIL= 3
No further improvement in the approximate solution X is
possible; XTOL is too small.
IFAIL= 4
The iteration is not making good progress. This failure exit
may indicate that the system does not have a zero, or that
the solution is very close to the origin (see Section 7).
Otherwise, rerunning C05NBF from a different starting point
may avoid the region of difficulty.
7. Accuracy
^
If x is the true solution, C05NBF tries to ensure that
^ ^
||x-x||<=XTOL*||x||.
-k
If this condition is satisfied with XTOL=10 , then the larger
components of x have k significant decimal digits. There is a
danger that the smaller components of x may have large relative
errors, but the fast rate of convergence of C05NBF usually avoids
this possibility.
If XTOL is less than machine precision, and the above test is
satisfied with the machine precision in place of XTOL, then the
routine exits with IFAIL = 3.
Note: this convergence test is based purely on relative error,
and may not indicate convergence if the solution is very close to
the origin.
The test assumes that the functions are reasonably well behaved.
If this condition is not satisfied, then C05NBF may incorrectly
indicate convergence. The validity of the answer can be checked,
for example, by rerunning C05NBF with a tighter tolerance.
8. Further Comments
The time required by C05NBF to solve a given problem depends on n
, the behaviour of the functions, the accuracy requested and the
starting point. The number of arithmetic operations executed by
2
C05NBF to process each call of FCN is about 11.5*n . Unless FCN
can be evaluated quickly, the timing of C05NBF will be strongly
influenced by the time spent in FCN.
Ideally the problem should be scaled so that at the solution the
function values are of comparable magnitude.
9. Example
To determine the values x ,..., x which satisfy the tridiagonal
1 9
equations:
(3-2x )x -2x =-1
1 1 2
-x -1+(3-2x )x -2x =-1, i=2,3,...,8
i i i i+1
-x +(3-2x )x =-1.
8 9 9
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc05pbf}{NAG On-line Documentation: c05pbf}
\beginscroll
\begin{verbatim}
C05PBF(3NAG) Foundation Library (12/10/92) C05PBF(3NAG)
C05 -- Roots of One or More Transcendental Equations C05PBF
C05PBF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C05PBF is an easy-to-use routine to find a solution of a system
of nonlinear equations by a modification of the Powell hybrid
method. The user must provide the Jacobian.
2. Specification
SUBROUTINE C05PBF (FCN, N, X, FVEC, FJAC, LDFJAC, XTOL,
1 WA, LWA, IFAIL)
INTEGER N, LDFJAC, LWA, IFAIL
DOUBLE PRECISION X(N), FVEC(N), FJAC(LDFJAC,N), XTOL, WA
1 (LWA)
EXTERNAL FCN
3. Description
The system of equations is defined as:
f (x ,x ,...,x )=0, i=1,2,...,n.
i 1 2 n
C05PBF is based upon the MINPACK routine HYBRJ1 (More et al [1]).
It chooses the correction at each step as a convex combination of
the Newton and scaled gradient directions. Under reasonable
conditions this guarantees global convergence for starting points
far from the solution and a fast rate of convergence. The
Jacobian is updated by the rank-1 method of Broyden. At the
starting point the Jacobian is calculated, but it is not
recalculated until the rank-1 method fails to produce
satisfactory progress. For more details see Powell [2].
4. References
[1] More J J, Garbow B S and Hillstrom K E User Guide for
MINPACK-1. Technical Report ANL-80-74. Argonne National
Laboratory.
[2] Powell M J D (1970) A Hybrid Method for Nonlinear Algebraic
Equations. Numerical Methods for Nonlinear Algebraic
Equations. (ed P Rabinowitz) Gordon and Breach.
5. Parameters
1: FCN -- SUBROUTINE, supplied by the user.
External Procedure
Depending upon the value of IFLAG, FCN must either return
the values of the functions f at a point x or return the
i
Jacobian at x.
Its specification is:
SUBROUTINE FCN (N, X, FVEC, FJAC, LDFJAC, IFLAG)
INTEGER N, LDFJAC, IFLAG
DOUBLE PRECISION X(N), FVEC(N), FJAC(LDFJAC,N)
1: N -- INTEGER Input
On entry: the number of equations, n.
2: X(N) -- DOUBLE PRECISION array Input
On entry: the components of the point x at which the
functions or the Jacobian must be evaluated.
3: FVEC(N) -- DOUBLE PRECISION array Output
On exit: if IFLAG = 1 on entry, FVEC must contain the
function values f (x) (unless IFLAG is set to a
i
negative value by FCN). If IFLAG = 2 on entry, FVEC
must not be changed.
4: FJAC(LDFJAC,N) -- DOUBLE PRECISION array Output
On exit: if IFLAG = 2 on entry, FJAC(i,j) must contain
ddf
i
the value of ---- at the point x, for i,j=1,2,...,n
ddx
j
(unless IFLAG is set to a negative value by FCN).
If IFLAG = 1 on entry, FJAC must not be changed.
5: LDFJAC -- INTEGER Input
On entry: the first dimension of FJAC.
6: IFLAG -- INTEGER Input/Output
On entry: IFLAG = 1 or 2:
if IFLAG = 1, FVEC is to be updated;
if IFLAG = 2, FJAC is to be updated.
On exit: in general, IFLAG should not be reset by FCN.
If, however, the user wishes to terminate execution
(perhaps because some illegal point x has been reached)
then IFLAG should be set to a negative integer. This
value will be returned through IFAIL.
FCN must be declared as EXTERNAL in the (sub)program
from which C05PBF is called. Parameters denoted as
Input must not be changed by this procedure.
2: N -- INTEGER Input
On entry: the number of equations, n. Constraint: N > 0.
3: X(N) -- DOUBLE PRECISION array Input/Output
On entry: an initial guess at the solution vector. On
exit: the final estimate of the solution vector.
4: FVEC(N) -- DOUBLE PRECISION array Output
On exit: the function values at the final point, X.
5: FJAC(LDFJAC,N) -- DOUBLE PRECISION array Output
On exit: the orthogonal matrix Q produced by the QR
factorization of the final approximate Jacobian.
6: LDFJAC -- INTEGER Input
On entry:
the first dimension of the array FJAC as declared in the
(sub)program from which C05PBF is called.
Constraint: LDFJAC >= N.
7: XTOL -- DOUBLE PRECISION Input
On entry: the accuracy in X to which the solution is
required. Suggested value: the square root of the machine
precision. Constraint: XTOL >= 0.0.
8: WA(LWA) -- DOUBLE PRECISION array Workspace
9: LWA -- INTEGER Input
On entry: the dimension of the array WA. Constraint:
LWA>=N*(N+13)/2.
10: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL< 0
A negative value of IFAIL indicates an exit from C05PBF
because the user has set IFLAG negative in FCN. The value of
IFAIL will be the same as the user's setting of IFLAG.
IFAIL= 1
On entry N <= 0,
or LDFJAC < N,
or XTOL < 0.0,
or LWA<N*(N+13)/2.
IFAIL= 2
There have been 100*(N+1) evaluations of the functions.
Consider restarting the calculation from the final point
held in X.
IFAIL= 3
No further improvement in the approximate solution X is
possible; XTOL is too small.
IFAIL= 4
The iteration is not making good progress. This failure exit
may indicate that the system does not have a zero or that
the solution is very close to the origin (see Section 7).
Otherwise, rerunning C05PBF from a different starting point
may avoid the region of difficulty.
7. Accuracy
^
If x is the true solution, C05PBF tries to ensure that
^ ^
||x-x|| <=XTOL*||x|| .
2 2
-k
If this condition is satisfied with XTOL=10 , then the larger
components of x have k significant decimal digits. There is a
danger that the smaller components of x may have large relative
errors, but the fast rate of convergence of C05PBF usually avoids
the possibility.
If XTOL is less than machine precision and the above test is
satisfied with the machine precision in place of XTOL, then the
routine exits with IFAIL = 3.
Note: this convergence test is based purely on relative error,
and may not indicate convergence if the solution is very close to
the origin.
The test assumes that the functions and Jacobian are coded
consistently and that the functions are reasonably well behaved.
If these conditions are not satisfied then C05PBF may incorrectly
indicate convergence. The coding of the Jacobian can be checked
using C05ZAF. If the Jacobian is coded correctly, then the
validity of the answer can be checked by rerunning C05PBF with a
tighter tolerance.
8. Further Comments
The time required by C05PBF to solve a given problem depends on n
, the behaviour of the functions, the accuracy requested and the
starting point. The number of arithmetic operations executed by
2
C05PBF is about 11.5*n to process each evaluation of the
3
functions and about 1.3*n to process each evaluation of the
Jacobian. Unless FCN can be evaluated quickly, the timing of
C05PBF will be strongly influenced by the time spent in FCN.
Ideally the problem should be scaled so that, at the solution,
the function values are of comparable magnitude.
9. Example
To determine the values x ,..., x which satisfy the tridiagonal
1 9
equations:
(3-2x )x -2x =-1
1 1 2
-x +(3-2x )x -2x =-1, i=2,3,...,8.
i-1 i i i+1
-x +(3-2x )x =-1.
8 9 9
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc05zaf}{NAG On-line Documentation: c05zaf}
\beginscroll
\begin{verbatim}
C05ZAF(3NAG) Foundation Library (12/10/92) C05ZAF(3NAG)
C05 -- Roots of One or More Transcendental Equations C05ZAF
C05ZAF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C05ZAF checks the user-provided gradients of a set of non-linear
functions in several variables, for consistency with the
functions themselves. The routine must be called twice.
2. Specification
SUBROUTINE C05ZAF (M, N, X, FVEC, FJAC, LDFJAC, XP, FVECP,
1 MODE, ERR)
INTEGER M, N, LDFJAC, MODE
DOUBLE PRECISION X(N), FVEC(M), FJAC(LDFJAC,N), XP(N),
1 FVECP(M), ERR(M)
3. Description
C05ZAF is based upon the MINPACK routine CHKDER (More et al [1]).
It checks the ith gradient for consistency with the ith function
by computing a forward-difference approximation along a suitably
chosen direction and comparing this approximation with the user-
supplied gradient along the same direction. The principal
characteristic of C05ZAF is its invariance under changes in scale
of the variables or functions.
4. References
[1] More J J, Garbow B S and Hillstrom K E User Guide for
MINPACK-1. Technical Report ANL-80-74. Argonne National
Laboratory.
5. Parameters
1: M -- INTEGER Input
On entry: the number of functions.
2: N -- INTEGER Input
On entry: the number of variables. For use with C05PBF and
C05PCF(*), M = N.
3: X(N) -- DOUBLE PRECISION array Input
On entry: the components of a point x, at which the
consistency check is to be made. (See Section 8.)
4: FVEC(M) -- DOUBLE PRECISION array Input
On entry: when MODE = 2, FVEC must contain the functions
evaluated at x.
5: FJAC(LDFJAC,N) -- DOUBLE PRECISION array Input
On entry: when MODE = 2, FJAC must contain the user-
supplied gradients. (The ith row of FJAC must contain the
gradient of the ith function evaluated at the point x.)
6: LDFJAC -- INTEGER Input
On entry:
the first dimension of the array FJAC as declared in the
(sub)program from which C05ZAF is called.
Constraint: LDFJAC >= M.
7: XP(N) -- DOUBLE PRECISION array Output
On exit: when MODE = 1, XP is set to a neighbouring point
to X.
8: FVECP(M) -- DOUBLE PRECISION array Input
On entry: when MODE = 2, FVECP must contain the functions
evaluated at XP.
9: MODE -- INTEGER Input
On entry: the value 1 on the first call and the value 2 on
the second call of C05ZAF.
10: ERR(M) -- DOUBLE PRECISION array Output
On exit: when MODE = 2, ERR contains measures of
correctness of the respective gradients. If there is no loss
of significance (see Section 8), then if ERR(i) is 1.0 the i
th user-supplied gradient is correct, whilst if ERR(i) is 0.
0 the ith gradient is incorrect. For values of ERR(i)
between 0.0 and 1.0 the categorisation is less certain. In
general, a value of ERR(i)>0.5 indicates that the ith
gradient is probably correct.
6. Error Indicators and Warnings
None.
7. Accuracy
See below.
8. Further Comments
The time required by C05ZAF increases with M and N.
C05ZAF does not perform reliably if cancellation or rounding
errors cause a severe loss of significance in the evaluation of a
function. Therefore, none of the components of x should be
unusually small (in particular, zero) or any other value which
may cause loss of significance. The relative differences between
corresponding elements of FVECP and FVEC should be at least two
orders of magnitude greater than the machine precision.
9. Example
This example checks the Jacobian matrix for a problem with 15
functions of 3 variables. The results indicate that the first 7
gradients are probably incorrect (this is caused by a deliberate
error in the code to calculate the Jacobian).
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06}{NAG On-line Documentation: c06}
\beginscroll
\begin{verbatim}
C06(3NAG) Foundation Library (12/10/92) C06(3NAG)
C06 -- Summation of Series Introduction -- C06
Chapter C06
Summation of Series
1. Scope of the Chapter
This chapter is concerned with calculating the discrete Fourier
transform of a sequence of real or complex data values, and
applying it to calculate convolutions and correlations.
2. Background to the Problems
2.1. Discrete Fourier Transforms
2.1.1. Complex transforms
Most of the routines in this chapter calculate the finite
discrete Fourier transform (DFT) of a sequence of n complex
numbers z , for j=0,1,...,n-1. The transform is defined by:
j
n-1
^ 1 -- ( 2(pi)jk)
z = --- > z exp(-i -------) (1)
k -- j ( n )
\/n j=0
for k=0,1,...,n-1. Note that equation (1) makes sense for all
^
integral k and with this extension z is periodic with period n,
k
^ ^ ^ ^
i.e. z =z , and in particular z =z .
k k+-n -k n-k
^ ^
If we write z =x +iy and z =a +ib , then the definition of z
j j j k k k k
may be written in terms of sines and cosines as:
n-1
1 -- ( ( 2(pi)jk) ( 2(pi)jk))
a = --- > (x cos( -------)+y sin( -------))
k -- ( j ( n ) j ( n ))
\/n j=0
n-1
1 -- ( ( 2(pi)jk) ( 2(pi)jk))
b = --- > (y cos( -------)-x sin( -------)).
k -- ( j ( n ) j ( n ))
\/n j=0
The original data values z may conversely be recovered from the
j
^
transform z by an inverse discrete Fourier transform:
k
n-1
1 -- ^ ( 2(pi)jk)
z = --- > z exp(+i -------) (2)
j -- k ( n )
\/n k=0
for j=0,1,...,n-1. If we take the complex conjugate of (2), we
^
find that the sequence z is the DFT of the sequence z . Hence
j k
^
the inverse DFT of the sequence z may be obtained by: taking the
k
^
complex conjugates of the z ; performing a DFT; and taking the
k
complex conjugates of the result.
Notes: definitions of the discrete Fourier transform vary.
Sometimes (2) is used as the definition of the DFT, and (1) as
the definition of the inverse. Also the scale-factor of 1/\/n may
be omitted in the definition of the DFT, and replaced by 1/n in
the definition of the inverse.
2.1.2. Real transforms
If the original sequence is purely real valued, i.e. z =x , then
j j
n-1
^ 1 -- ( 2(pi)jk)
z =a +ib = --- > x exp(-i -------)
k k k -- j ( n )
\/n j=0
^ ^
and z is the complex conjugate of z . Thus the DFT of a real
n-k k
sequence is a particular type of complex sequence, called a
Hermitian sequence, or half-complex or conjugate symmetric with
the properties:
a =a b =-b b =0 and, if n is even, b =0.
n-k k n-k k 0 n/2
Thus a Hermitian sequence of n complex data values can be
represented by only n, rather than 2n, independent real values.
This can obviously lead to economies in storage, the following
scheme being used in this chapter: the real parts a for
k
0<=k<=n/2 are stored in normal order in the first n/2+1 locations
of an array X of length n; the corresponding non-zero imaginary
parts are stored in reverse order in the remaining locations of
X. In other words, if X is declared with bounds (0:n-1) in the
^
user's (sub)program, the real and imaginary parts of z are
k
stored as follows:
if n=2s if n=2s-1
X(0) a a
0 0
X(1) a a
1 1
X(2) a a
2 2
. . .
. . .
. . .
X(s-1) a a
s-1 s-1
X(s) a b
s s-1
X(s+1) b b
s-1 s-2
. . .
. . .
. . .
X(n-2) b b
2 2
X(n-1) b b
1 1
( n/2-1 )
1 ( -- ( ( 2(pi)jk) ( 2(pi)jk)) )
Hence x = ---(a +2 > (a cos( -------)-b sin( -------))+a )
j ( 0 -- ( k ( n ) k ( n )) n/2)
\/n( k=0 )
where a = 0 if n is odd.
n/2
2.1.3. Fourier integral transforms
The usual application of the discrete Fourier transform is that
of obtaining an approximation of the Fourier integral transform
+infty
/
F(s)= | f(t)exp(-i2(pi)st)dt
/
-infty
when f(t) is negligible outside some region (0,c). Dividing the
region into n equal intervals we have
n-1
c --
F(s)~= - > f exp(-i2(pi)sjc/n)
n -- j
j=0
and so
n-1
c --
F ~= - > f exp(-i2(pi)jk/n)
k n -- j
j=0
for k=0,1,...,n-1, where f =f(jc/n) and F =F(k/c).
j k
Hence the discrete Fourier transform gives an approximation to
the Fourier integral transform in the region s=0 to s=n/c.
If the function f(t) is defined over some more general interval
(a,b), then the integral transform can still be approximated by
the discrete transform provided a shift is applied to move the
point a to the origin.
2.1.4. Convolutions and correlations
One of the most important applications of the discrete Fourier
transform is to the computation of the discrete convolution or
correlation of two vectors x and y defined (as in Brigham [1])
by:
n-1
--
convolution: z = > x y
k -- j k-j
j=0
n-1
--
correlation: w = > x y
k -- j k+j
j=0
(Here x and y are assumed to be periodic with period n.)
Under certain circumstances (see Brigham [1]) these can be used
as approximations to the convolution or correlation integrals
defined by:
+infty
/
z(s)= | x(t)y(s-t)dt
/
-infty
and
+infty
/
w(s)= | x(t)y(s+t)dt, -infty<s<+infty.
/
-infty
For more general advice on the use of Fourier transforms, see
Hamming [2]; more detailed information on the fast Fourier
transform algorithm can be found in Van Loan [3] and Brigham [1].
2.2. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
[2] Hamming R W (1962) Numerical Methods for Scientists and
Engineers. McGraw-Hill.
[3] Van Loan C (1992) Computational Frameworks for the Fast
Fourier Transform. SIAM Philadelphia.
3. Recommendations on Choice and Use of Routines
3.1. One-dimensional Fourier Transforms
The choice of routine is determined first of all by whether the
data values constitute a real, Hermitian or general complex
sequence. It is wasteful of time and storage to use an
inappropriate routine.
Two groups, each of three routines, are provided
Group 1 Group 2
Real sequences C06EAF C06FPF
Hermitian sequences C06EBF C06FQF
General complex C06ECF C06FRF
sequences
Group 1 routines each compute a single transform of length n,
without requiring any extra working storage. The Group 1 routines
impose some restrictions on the value of n, namely that no prime
factor of n may exceed 19 and the total number of prime factors
(including repetitions) may not exceed 20 (though the latter
6
restriction only becomes relevant when n>10 ).
Group 2 routines are designed to perform several transforms in a
single call, all with the same value of n. They do however
require more working storage. Even on scalar processors, they may
be somewhat faster than repeated calls to Group 1 routines
because of reduced overheads and because they pre-compute and
store the required values of trigonometric functions. Group 2
routines impose no practical restrictions on the value of n;
however the fast Fourier transform algorithm ceases to be 'fast'
if applied to values of n which cannot be expressed as a product
of small prime factors. All the above routines are particularly
efficient if the only prime factors of n are 2, 3 or 5.
If extensive use is to be made of these routines, users who are
concerned about efficiency are advised to conduct their own
timing tests.
To compute inverse discrete Fourier transforms the above routines
should be used in conjunction with the utility routines C06GBF,
C06GCF and C06GQF which form the complex conjugate of a Hermitian
or general sequence of complex data values.
3.2. Multi-dimensional Fourier Transforms
C06FUF computes a 2-dimensional discrete Fourier transform of a
2-dimensional sequence of complex data values. This is defined by
n -1 n -1
1 2 ( 2(pi)j k ) ( 2(pi)j k )
^ 1 -- -- ( 1 1) ( 2 2)
z = ------- > > z exp(-i ---------)exp(-i ---------).
-- -- ( n ) ( n )
k k /n n j =0 j =0 j j ( 1 ) ( 2 )
1 2 \/ 1 2 1 2 1 2
3.3. Convolution and Correlation
C06EKF computes either the discrete convolution or the discrete
correlation of two real vectors.
3.4. Index
Complex conjugate,
complex sequence C06GCF
Hermitian sequence C06GBF
multiple Hermitian sequences C06GQF
Complex sequence from Hermitian sequences C06GSF
Convolution or Correlation
real vectors C06EKF
Discrete Fourier Transform
two-dimensional
complex sequence C06FUF
one-dimensional, multiple transforms
complex sequence C06FRF
Hermitian sequence C06FQF
real sequence C06FPF
one-dimensional, single transforms
complex sequence C06ECF
Hermitian sequence C06EBF
real sequence C06EAF
C06 -- Summation of Series Contents -- C06
Chapter C06
Summation of Series
C06EAF Single 1-D real discrete Fourier transform, no extra
workspace
C06EBF Single 1-D Hermitian discrete Fourier transform, no extra
workspace
C06ECF Single 1-D complex discrete Fourier transform, no extra
workspace
C06EKF Circular convolution or correlation of two real vectors,
no extra workspace
C06FPF Multiple 1-D real discrete Fourier transforms
C06FQF Multiple 1-D Hermitian discrete Fourier transforms
C06FRF Multiple 1-D complex discrete Fourier transforms
C06FUF 2-D complex discrete Fourier transform
C06GBF Complex conjugate of Hermitian sequence
C06GCF Complex conjugate of complex sequence
C06GQF Complex conjugate of multiple Hermitian sequences
C06GSF Convert Hermitian sequences to general complex sequences
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06eaf}{NAG On-line Documentation: c06eaf}
\beginscroll
\begin{verbatim}
C06EAF(3NAG) Foundation Library (12/10/92) C06EAF(3NAG)
C06 -- Summation of Series C06EAF
C06EAF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06EAF calculates the discrete Fourier transform of a sequence of
n real data values. (No extra workspace required.)
2. Specification
SUBROUTINE C06EAF (X, N, IFAIL)
INTEGER N, IFAIL
DOUBLE PRECISION X(N)
3. Description
Given a sequence of n real data values x , for j=0,1,...,n-1,
j
this routine calculates their discrete Fourier transform defined
by:
n-1
^ 1 -- ( 2(pi)jk)
z = --- > x *exp(-i -------), k=0,1,...,n-1.
k -- j ( n )
\/n j=0
1
(Note the scale factor of --- in this definition.) The
\/n
^
transformed values z are complex, but they form a Hermitian
k
^ ^
sequence (i.e., z is the complex conjugate of z ), so they are
n-k k
completely determined by n real numbers (see also the Chapter
Introduction).
To compute the inverse discrete Fourier transform defined by:
n-1
^ 1 -- ( 2(pi)jk)
w = --- > x *exp(+i -------),
k -- j ( n )
\/n j=0
this routine should be followed by a call of C06GBF to form the
^
complex conjugates of the z .
k
The routine uses the fast Fourier transform (FFT) algorithm
(Brigham [1]). There are some restrictions on the value of n (see
Section 5).
4. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
5. Parameters
1: X(N) -- DOUBLE PRECISION array Input/Output
On entry: if X is declared with bounds (0:N-1) in the (sub)
program from which C06EAF is called, then X(j) must contain
x , for j=0,1,...,n-1. On exit: the discrete Fourier
j
transform stored in Hermitian form. If the components of the
^
transform z are written as a +ib , and if X is declared
k k k
with bounds (0:N-1) in the (sub)program from which C06EAF is
called, then for 0<=k<=n/2, a is contained in X(k), and for
k
1<=k<=(n-1)/2, b is contained in X(n-k). (See also Section
k
2.1.2 of the Chapter Introduction, and the Example Program.)
2: N -- INTEGER Input
On entry: the number of data values, n. The largest prime
factor of N must not exceed 19, and the total number of
prime factors of N, counting repetitions, must not exceed
20. Constraint: N > 1.
3: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
IFAIL= 1
At least one of the prime factors of N is greater than 19.
IFAIL= 2
N has more than 20 prime factors.
IFAIL= 3
N <= 1.
7. Accuracy
Some indication of accuracy can be obtained by performing a
subsequent inverse transform and comparing the results with the
original sequence (in exact arithmetic they would be identical).
8. Further Comments
The time taken by the routine is approximately proportional to
n*logn, but also depends on the factorization of n. The routine
is somewhat faster than average if the only prime factors of n
are 2, 3 or 5; and fastest of all if n is a power of 2.
On the other hand, the routine is particularly slow if n has
several unpaired prime factors, i.e., if the 'square-free' part
of n has several factors. For such values of n, routine C06FAF(*)
(which requires an additional n elements of workspace) is
considerably faster.
9. Example
This program reads in a sequence of real data values, and prints
their discrete Fourier transform (as computed by C06EAF), after
expanding it from Hermitian form into a full complex sequence.
It then performs an inverse transform using C06GBF and C06EBF,
and prints the sequence so obtained alongside the original data
values.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06ebf}{NAG On-line Documentation: c06ebf}
\beginscroll
\begin{verbatim}
C06EBF(3NAG) Foundation Library (12/10/92) C06EBF(3NAG)
C06 -- Summation of Series C06EBF
C06EBF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06EBF calculates the discrete Fourier transform of a Hermitian
sequence of n complex data values. (No extra workspace required.)
2. Specification
SUBROUTINE C06EBF (X, N, IFAIL)
INTEGER N, IFAIL
DOUBLE PRECISION X(N)
3. Description
Given a Hermitian sequence of n complex data values z (i.e., a
j
sequence such that z is real and z is the complex conjugate
0 n-j
of z , for j=1,2,...,n-1) this routine calculates their discrete
j
Fourier transform defined by:
n-1
^ 1 -- ( 2(pi)jk)
x = --- > z *exp(-i -------), k=0,1,...,n-1.
k -- j ( n )
\/n j=0
1
(Note the scale factor of --- in this definition.) The
\/n
^
transformed values x are purely real (see also the the Chapter
k
Introduction).
To compute the inverse discrete Fourier transform defined by:
n-1
^ 1 -- ( 2(pi)jk)
y = --- > z *exp(+i -------),
k -- j ( n )
\/n j=0
this routine should be preceded by a call of C06GBF to form the
complex conjugates of the z .
j
The routine uses the fast Fourier transform (FFT) algorithm
(Brigham [1]). There are some restrictions on the value of n (see
Section 5).
4. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
5. Parameters
1: X(N) -- DOUBLE PRECISION array Input/Output
On entry: the sequence to be transformed stored in
Hermitian form. If the data values z are written as x +iy ,
j j j
and if X is declared with bounds (0:N-1) in the subroutine
from which C06EBF is called, then for 0<=j<=n/2, x is
j
contained in X(j), and for 1<=j<=(n-1)/2, y is contained in
j
X(n-j). (See also Section 2.1.2 of the Chapter Introduction
and the Example Program.) On exit: the components of the
^
discrete Fourier transform x . If X is declared with bounds
k
(0:N-1) in the (sub)program from which C06EBF is called,
^
then x is stored in X(k), for k=0,1,...,n-1.
k
2: N -- INTEGER Input
On entry: the number of data values, n. The largest prime
factor of N must not exceed 19, and the total number of
prime factors of N, counting repetitions, must not exceed
20. Constraint: N > 1.
3: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
IFAIL= 1
At least one of the prime factors of N is greater than 19.
IFAIL= 2
N has more than 20 prime factors.
IFAIL= 3
N <= 1.
7. Accuracy
Some indication of accuracy can be obtained by performing a
subsequent inverse transform and comparing the results with the
original sequence (in exact arithmetic they would be identical).
8. Further Comments
The time taken by the routine is approximately proportional to
n*logn, but also depends on the factorization of n. The routine
is somewhat faster than average if the only prime factors of n
are 2, 3 or 5; and fastest of all if n is a power of 2.
On the other hand, the routine is particularly slow if n has
several unpaired prime factors, i.e., if the 'square-free' part
of n has several factors. For such values of n, routine C06FBF(*)
(which requires an additional n elements of workspace) is
considerably faster.
9. Example
This program reads in a sequence of real data values which is
assumed to be a Hermitian sequence of complex data values stored
in Hermitian form. The input sequence is expanded into a full
complex sequence and printed alongside the original sequence. The
discrete Fourier transform (as computed by C06EBF) is printed
out.
The program then performs an inverse transform using C06EAF and
C06GBF, and prints the sequence so obtained alongside the
original data values.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06ecf}{NAG On-line Documentation: c06ecf}
\beginscroll
\begin{verbatim}
C06ECF(3NAG) Foundation Library (12/10/92) C06ECF(3NAG)
C06 -- Summation of Series C06ECF
C06ECF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06ECF calculates the discrete Fourier transform of a sequence of
n complex data values. (No extra workspace required.)
2. Specification
SUBROUTINE C06ECF (X, Y, N, IFAIL)
INTEGER N, IFAIL
DOUBLE PRECISION X(N), Y(N)
3. Description
Given a sequence of n complex data values z , for j=0,1,...,n-1,
j
this routine calculates their discrete Fourier transform defined
by:
n-1
^ 1 -- ( 2(pi)jk)
z = --- > z *exp(-i -------), k=0,1,...,n-1.
k -- j ( n )
\/n j=0
1
(Note the scale factor of --- in this definition.)
\/n
To compute the inverse discrete Fourier transform defined by:
n-1
^ 1 -- ( 2(pi)jk)
w = --- > z *exp(+i -------),
k -- j ( n )
\/n j=0
this routine should be preceded and followed by calls of C06GCF
^
to form the complex conjugates of the z and the z .
j k
The routine uses the fast Fourier transform (FFT) algorithm
(Brigham [1]). There are some restrictions on the value of n (see
Section 5).
4. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
5. Parameters
1: X(N) -- DOUBLE PRECISION array Input/Output
On entry: if X is declared with bounds (0:N-1) in the (sub)
program from which C06ECF is called, then X(j) must contain
x , the real part of z , for j=0,1,...,n-1. On exit: the
j j
real parts a of the components of the discrete Fourier
k
transform. If X is declared with bounds (0:N-1) in the (sub)
program from which C06ECF is called, then a is contained in
k
X(k), for k=0,1,...,n-1.
2: Y(N) -- DOUBLE PRECISION array Input/Output
On entry: if Y is declared with bounds (0:N-1) in the (sub)
program from which C06ECF is called, then Y(j) must contain
y , the imaginary part of z , for j=0,1,...,n-1. On exit:
j j
the imaginary parts b of the components of the discrete
k
Fourier transform. If Y is declared with bounds (0:N-1) in
the (sub)program from which C06ECF is called, then b is
k
contained in Y(k), for k=0,1,...,n-1.
3: N -- INTEGER Input
On entry: the number of data values, n. The largest prime
factor of N must not exceed 19, and the total number of
prime factors of N, counting repetitions, must not exceed
20. Constraint: N > 1.
4: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
IFAIL= 1
At least one of the prime factors of N is greater than 19.
IFAIL= 2
N has more than 20 prime factors.
IFAIL= 3
N <= 1.
7. Accuracy
Some indication of accuracy can be obtained by performing a
subsequent inverse transform and comparing the results with the
original sequence (in exact arithmetic they would be identical).
8. Further Comments
The time taken by the routine is approximately proportional to
n*logn, but also depends on the factorization of n. The routine
is somewhat faster than average if the only prime factors of n
are 2, 3 or 5; and fastest of all if n is a power of 2.
On the other hand, the routine is particularly slow if n has
several unpaired prime factors, i.e., if the 'square-free' part
of n has several factors. For such values of n, routine C06FCF(*)
(which requires an additional n real elements of workspace) is
considerably faster.
9. Example
This program reads in a sequence of complex data values and
prints their discrete Fourier transform.
It then performs an inverse transform using C06GCF and C06ECF,
and prints the sequence so obtained alongside the original data
values.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06ekf}{NAG On-line Documentation: c06ekf}
\beginscroll
\begin{verbatim}
C06EKF(3NAG) Foundation Library (12/10/92) C06EKF(3NAG)
C06 -- Summation of Series C06EKF
C06EKF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06EKF calculates the circular convolution or correlation of two
real vectors of period n. No extra workspace is required.
2. Specification
SUBROUTINE C06EKF (JOB, X, Y, N, IFAIL)
INTEGER JOB, N, IFAIL
DOUBLE PRECISION X(N), Y(N)
3. Description
This routine computes:
if JOB =1, the discrete convolution of x and y, defined by:
n-1 n-1
-- --
z = > x y = > x y ;
k -- j k-j -- k-j j
j=0 j=0
if JOB =2, the discrete correlation of x and y defined by:
n-1
--
w = > x y .
k -- j k+j
j=0
Here x and y are real vectors, assumed to be periodic, with
period n, i.e., x =x =x =...; z and w are then also
j j+-n j+-2n
periodic with period n.
Note: this usage of the terms 'convolution' and 'correlation' is
taken from Brigham [1]. The term 'convolution' is sometimes used
to denote both these computations.
^ ^ ^ ^
If x, y, z and w are the discrete Fourier transforms of these
sequences,
n-1
^ 1 -- ( 2(pi)jk)
i.e., x = --- > x *exp(-i -------), etc,
k -- j ( n )
\/n j=0
^ ^ ^
then z =\/n.x y
k k k
^ ^ ^
and w =\/n.x y
k k k
(the bar denoting complex conjugate).
This routine calls the same auxiliary routines as C06EAF and
C06EBF to compute discrete Fourier transforms, and there are some
restrictions on the value of n.
4. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
5. Parameters
1: JOB -- INTEGER Input
On entry: the computation to be performed:
n-1
--
if JOB = 1, z = > x y (convolution);
k -- j k-j
j=0
n-1
--
if JOB = 2, w = > x y (correlation).
k -- j k+j
j=0
Constraint: JOB = 1 or 2.
2: X(N) -- DOUBLE PRECISION array Input/Output
On entry: the elements of one period of the vector x. If X
is declared with bounds (0:N-1) in the (sub)program from
which C06EKF is called, then X(j) must contain x , for
j
j=0,1,...,n-1. On exit: the corresponding elements of the
discrete convolution or correlation.
3: Y(N) -- DOUBLE PRECISION array Input/Output
On entry: the elements of one period of the vector y. If Y
is declared with bounds (0:N-1) in the (sub)program from
which C06EKF is called, then Y(j) must contain y , for
j
j=0,1,...,n-1. On exit: the discrete Fourier transform of
the convolution or correlation returned in the array X; the
transform is stored in Hermitian form, exactly as described
in the document C06EAF.
4: N -- INTEGER Input
On entry: the number of values, n, in one period of the
vectors X and Y. The largest prime factor of N must not
exceed 19, and the total number of prime factors of N,
counting repetitions, must not exceed 20. Constraint: N > 1.
5: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
IFAIL= 1
At least one of the prime factors of N is greater than 19.
IFAIL= 2
N has more than 20 prime factors.
IFAIL= 3
N <= 1.
IFAIL= 4
JOB /= 1 or 2.
7. Accuracy
The results should be accurate to within a small multiple of the
machine precision.
8. Further Comments
The time taken by the routine is approximately proportional to
n*logn, but also depends on the factorization of n. The routine
is faster than average if the only prime factors are 2, 3 or 5;
and fastest of all if n is a power of 2.
The routine is particularly slow if n has several unpaired prime
factors, i.e., if the 'square free' part of n has several
factors. For such values of n, routine C06FKF(*) is considerably
faster (but requires an additional workspace of n elements).
9. Example
This program reads in the elements of one period of two real
vectors x and y and prints their discrete convolution and
correlation (as computed by C06EKF). In realistic computations
the number of data values would be much larger.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06fpf}{NAG On-line Documentation: c06fpf}
\beginscroll
\begin{verbatim}
C06FPF(3NAG) Foundation Library (12/10/92) C06FPF(3NAG)
C06 -- Summation of Series C06FPF
C06FPF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06FPF computes the discrete Fourier transforms of m sequences,
each containing n real data values. This routine is designed to
be particularly efficient on vector processors.
2. Specification
SUBROUTINE C06FPF (M, N, X, INIT, TRIG, WORK, IFAIL)
INTEGER M, N, IFAIL
DOUBLE PRECISION X(M*N), TRIG(2*N), WORK(M*N)
CHARACTER*1 INIT
3. Description
p
Given m sequences of n real data values x , for j=0,1,...,n-1;
j
p=1,2,...,m, this routine simultaneously calculates the Fourier
transforms of all the sequences defined by:
n-1
^p 1 -- p ( 2(pi)jk)
z = --- > x *exp(-i -------), k=0,1,...,n-1; p=1,2,...,m.
k -- j ( n )
\/n j=0
1
(Note the scale factor --- in this definition.)
\/n
^p
The transformed values z are complex, but for each value of p
k
^p ^p
the z form a Hermitian sequence (i.e.,z is the complex
k n-k
^p
conjugate of z ), so they are completely determined by mn real
k
numbers (see also the Chapter Introduction).
The discrete Fourier transform is sometimes defined using a
positive sign in the exponential term:
n-1
^p 1 -- p ( 2(pi)jk)
z = --- > x *exp(+i -------).
k -- j ( n )
\/n j=0
To compute this form, this routine should be followed by a call
^p
to C06GQF to form the complex conjugates of the z .
k
The routine uses a variant of the fast Fourier transform (FFT)
algorithm (Brigham [1]) known as the Stockham self-sorting
algorithm, which is described in Temperton [2]. Special coding is
provided for the factors 2, 3, 4, 5 and 6. This routine is
designed to be particularly efficient on vector processors, and
it becomes especially fast as M, the number of transforms to be
computed in parallel, increases.
4. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
[2] Temperton C (1983) Fast Mixed-Radix Real Fourier Transforms.
J. Comput. Phys. 52 340--350.
5. Parameters
1: M -- INTEGER Input
On entry: the number of sequences to be transformed, m.
Constraint: M >= 1.
2: N -- INTEGER Input
On entry: the number of real values in each sequence, n.
Constraint: N >= 1.
3: X(M,N) -- DOUBLE PRECISION array Input/Output
On entry: the data must be stored in X as if in a two-
dimensional array of dimension (1:M,0:N-1); each of the m
sequences is stored in a row of the array. In other words,
if the data values of the pth sequence to be transformed are
p
denoted by x , for j=0,1,...,n-1, then the mn elements of
j
the array X must contain the values
1 2 m 1 2 m 1 2 m
x ,x ,...,x , x ,x ,..., x ,...,x ,x ,...,x .
0 0 0 1 1 1 n-1 n-1 n-1
On exit: the m discrete Fourier transforms stored as if in
a two-dimensional array of dimension (1:M,0:N-1). Each of
the m transforms is stored in a row of the array in
Hermitian form, overwriting the corresponding original
sequence. If the n components of the discrete Fourier
^p p p p
transform z are written as a +ib , then for 0<=k<=n/2, a
k k k k
p
is contained in X(p,k), and for 1<=k<=(n-1)/2, b is
k
contained in X(p,n-k). (See also Section 2.1.2 of the
Chapter Introduction.)
4: INIT -- CHARACTER*1 Input
On entry: if the trigonometric coefficients required to
compute the transforms are to be calculated by the routine
and stored in the array TRIG, then INIT must be set equal to
'I' (Initial call).
If INIT contains 'S' (Subsequent call), then the routine
assumes that trigonometric coefficients for the specified
value of n are supplied in the array TRIG, having been
calculated in a previous call to one of C06FPF, C06FQF or
C06FRF.
If INIT contains 'R' (Restart then the routine assumes that
trigonometric coefficients for the particular value of n are
supplied in the array TRIG, but does not check that C06FPF,
C06FQF or C06FRF have previously been called. This option
allows the TRIG array to be stored in an external file, read
in and re-used without the need for a call with INIT equal
to 'I'. The routine carries out a simple test to check that
the current value of n is consistent with the array TRIG.
Constraint: INIT = 'I', 'S' or 'R'.
5: TRIG(2*N) -- DOUBLE PRECISION array Input/Output
On entry: if INIT = 'S' or 'R', TRIG must contain the
required coefficients calculated in a previous call of the
routine. Otherwise TRIG need not be set. On exit: TRIG
contains the required coefficients (computed by the routine
if INIT = 'I').
6: WORK(M*N) -- DOUBLE PRECISION array Workspace
7: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL= 1
On entry M < 1.
IFAIL= 2
N < 1.
IFAIL= 3
INIT is not one of 'I', 'S' or 'R'.
IFAIL= 4
INIT = 'S', but none of C06FPF, C06FQF or C06FRF has
previously been called.
IFAIL= 5
INIT = 'S' or 'R', but the array TRIG and the current value
of N are inconsistent.
7. Accuracy
Some indication of accuracy can be obtained by performing a
subsequent inverse transform and comparing the results with the
original sequence (in exact arithmetic they would be identical).
8. Further Comments
The time taken by the routine is approximately proportional to
nm*logn, but also depends on the factors of n. The routine is
fastest if the only prime factors of n are 2, 3 and 5, and is
particularly slow if n is a large prime, or has large prime
factors.
9. Example
This program reads in sequences of real data values and prints
their discrete Fourier transforms (as computed by C06FPF). The
Fourier transforms are expanded into full complex form using
C06GSF and printed. Inverse transforms are then calculated by
calling C06GQF followed by C06FQF showing that the original
sequences are restored.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06fqf}{NAG On-line Documentation: c06fqf}
\beginscroll
\begin{verbatim}
C06FQF(3NAG) Foundation Library (12/10/92) C06FQF(3NAG)
C06 -- Summation of Series C06FQF
C06FQF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06FQF computes the discrete Fourier transforms of m Hermitian
sequences, each containing n complex data values. This routine is
designed to be particularly efficient on vector processors.
2. Specification
SUBROUTINE C06FQF (M, N, X, INIT, TRIG, WORK, IFAIL)
INTEGER M, N, IFAIL
DOUBLE PRECISION X(M*N), TRIG(2*N), WORK(M*N)
CHARACTER*1 INIT
3. Description
p
Given m Hermitian sequences of n complex data values z , for
j
j=0,1,...,n-1; p=1,2,...,m, this routine simultaneously
calculates the Fourier transforms of all the sequences defined
by:
n-1
^p 1 -- p ( 2(pi)jk)
x = --- > z *exp(-i -------), k=0,1,...,n-1; p=1,2,...,m.
k -- j ( n )
\/n j=0
1
(Note the scale factor --- in this definition.)
\/n
The transformed values are purely real (see also the Chapter
Introduction).
The discrete Fourier transform is sometimes defined using a
positive sign in the exponential term
n-1
^p 1 -- p ( 2(pi)jk)
x = --- > z *exp(+i -------).
k -- j ( n )
\/n j=0
To compute this form, this routine should be preceded by a call
^p
to C06GQF to form the complex conjugates of the z .
j
The routine uses a variant of the fast Fourier transform (FFT)
algorithm (Brigham [1]) known as the Stockham self-sorting
algorithm, which is described in Temperton [2]. Special code is
included for the factors 2, 3, 4, 5 and 6. This routine is
designed to be particularly efficient on vector processors, and
it becomes especially fast as m, the number of transforms to be
computed in parallel, increases.
4. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
[2] Temperton C (1983) Fast Mixed-Radix Real Fourier Transforms.
J. Comput. Phys. 52 340--350.
5. Parameters
1: M -- INTEGER Input
On entry: the number of sequences to be transformed, m.
Constraint: M >= 1.
2: N -- INTEGER Input
On entry: the number of data values in each sequence, n.
Constraint: N >= 1.
3: X(M,N) -- DOUBLE PRECISION array Input/Output
On entry: the data must be stored in X as if in a two-
dimensional array of dimension (1:M,0:N-1); each of the m
sequences is stored in a row of the array in Hermitian form.
p p p
If the n data values z are written as x +iy , then for
j j j
p
0<=j<=n/2, x is contained in X(p,j), and for 1<=j<=(n-1)/2,
j
p
y is contained in X(p,n-j). (See also Section 2.1.2 of the
j
Chapter Introduction.) On exit: the components of the m
discrete Fourier transforms, stored as if in a two-
dimensional array of dimension (1:M,0:N-1). Each of the m
transforms is stored as a row of the array, overwriting the
corresponding original sequence. If the n components of the
^p
discrete Fourier transform are denoted by x , for
k
k=0,1,...,n-1, then the mn elements of the array X contain
the values
^1 ^2 ^m ^1 ^2 ^m ^1 ^2 ^m
x ,x ,...,x , x ,x ,..., x ,...,x ,x ,...,x .
0 0 0 1 1 1 n-1 n-1 n-1
4: INIT -- CHARACTER*1 Input
On entry: if the trigonometric coefficients required to
compute the transforms are to be calculated by the routine
and stored in the array TRIG, then INIT must be set equal to
'I' (Initial call).
If INIT contains 'S' (Subsequent call), then the routine
assumes that trigonometric coefficients for the specified
value of n are supplied in the array TRIG, having been
calculated in a previous call to one of C06FPF, C06FQF or
C06FRF.
If INIT contains 'R' (Restart), then the routine assumes
that trigonometric coefficients for the particular value of
N are supplied in the array TRIG, but does not check that
C06FPF, C06FQF or C06FRF have previously been called. This
option allows the TRIG array to be stored in an external
file, read in and re-used without the need for a call with
INIT equal to 'I'. The routine carries out a simple test to
check that the current value of n is compatible with the
array TRIG. Constraint: INIT = 'I', 'S' or 'R'.
5: TRIG(2*N) -- DOUBLE PRECISION array Input/Output
On entry: if INIT = 'S' or 'R', TRIG must contain the
required coefficients calculated in a previous call of the
routine. Otherwise TRIG need not be set. On exit: TRIG
contains the required coefficients (computed by the routine
if INIT = 'I').
6: WORK(M*N) -- DOUBLE PRECISION array Workspace
7: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL= 1
On entry M < 1.
IFAIL= 2
On entry N < 1.
IFAIL= 3
On entry INIT is not one of 'I', 'S' or 'R'.
IFAIL= 4
On entry INIT = 'S', but none of C06FPF, C06FQF and C06FRF
has previously been called.
IFAIL= 5
On entry INIT = 'S' or 'R', but the array TRIG and the
current value of n are inconsistent.
7. Accuracy
Some indication of accuracy can be obtained by performing a
subsequent inverse transform and comparing the results with the
original sequence (in exact arithmetic they would be identical).
8. Further Comments
The time taken by the routine is approximately proportional to
nm*logn, but also depends on the factors of n. The routine is
fastest if the only prime factors of n are 2, 3 and 5, and is
particularly slow if n is a large prime, or has large prime
factors.
9. Example
This program reads in sequences of real data values which are
assumed to be Hermitian sequences of complex data stored in
Hermitian form. The sequences are expanded into full complex form
using C06GSF and printed. The discrete Fourier transforms are
then computed (using C06FQF) and printed out. Inverse transforms
are then calculated by calling C06FPF followed by C06GQF showing
that the original sequences are restored.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06frf}{NAG On-line Documentation: c06frf}
\beginscroll
\begin{verbatim}
C06FRF(3NAG) Foundation Library (12/10/92) C06FRF(3NAG)
C06 -- Summation of Series C06FRF
C06FRF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06FRF computes the discrete Fourier transforms of m sequences,
each containing n complex data values. This routine is designed
to be particularly efficient on vector processors.
2. Specification
SUBROUTINE C06FRF (M, N, X, Y, INIT, TRIG, WORK, IFAIL)
INTEGER M, N, IFAIL
DOUBLE PRECISION X(M*N), Y(M*N), TRIG(2*N), WORK(2*M*N)
CHARACTER*1 INIT
3. Description
p
Given m sequences of n complex data values z , for j=0,1,...,n-1;
j
p=1,2,...,m, this routine simultaneously calculates the Fourier
transforms of all the sequences defined by:
n-1
^p 1 -- p ( 2(pi)jk)
z = --- > z *exp(-i -------), k=0,1,...,n-1; p=1,2,...,m.
k -- j ( n )
\/n j=0
1
(Note the scale factor --- in this definition.)
\/n
The discrete Fourier transform is sometimes defined using a
positive sign in the exponential term
n-1
^p 1 -- p ( 2(pi)jk)
z = --- > z *exp(+i -------).
k -- j ( n )
\/n j=0
To compute this form, this routine should be preceded and
followed by a call of C06GCF to form the complex conjugates of
p ^p
the z and the z .
j k
The routine uses a variant of the fast Fourier transform (FFT)
algorithm (Brigham [1]) known as the Stockham self-sorting
algorithm, which is described in Temperton [2]. Special code is
provided for the factors 2, 3, 4, 5 and 6. This routine is
designed to be particularly efficient on vector processors, and
it becomes especially fast as m, the number of transforms to be
computed in parallel, increases.
4. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
[2] Temperton C (1983) Self-sorting Mixed-radix Fast Fourier
Transforms. J. Comput. Phys. 52 1--23.
5. Parameters
1: M -- INTEGER Input
On entry: the number of sequences to be transformed, m.
Constraint: M >= 1.
2: N -- INTEGER Input
On entry: the number of complex values in each sequence, n.
Constraint: N >= 1.
3: X(M,N) -- DOUBLE PRECISION array Input/Output
4: Y(M,N) -- DOUBLE PRECISION array Input/Output
On entry: the real and imaginary parts of the complex data
must be stored in X and Y respectively as if in a two-
dimensional array of dimension (1:M,0:N-1); each of the m
sequences is stored in a row of each array. In other words,
if the real parts of the pth sequence to be transformed are
p
denoted by x , for j=0,1,...,n-1, then the mn elements of
j
the array X must contain the values
1 2 m 1 2 m 1 2 m
x ,x ,...,x , x ,x ,...,x ,..., x ,x ,...,x .
0 0 0 1 1 1 n-1 n-1 n-1
On exit: X and Y are overwritten by the real and imaginary
parts of the complex transforms.
5: INIT -- CHARACTER*1 Input
On entry: if the trigonometric coefficients required to
compute the transforms are to be calculated by the routine
and stored in the array TRIG, then INIT must be set equal to
'I' (Initial call).
If INIT contains 'S' (Subsequent call), then the routine
assumes that trigonometric coefficients for the specified
value of n are supplied in the array TRIG, having been
calculated in a previous call to one of C06FPF, C06FQF or
C06FRF.
If INIT contains 'R' (Restart) then the routine assumes that
trigonometric coefficients for the particular value of n are
supplied in the array TRIG, but does not check that C06FPF,
C06FQF or C06FRF have previously been called. This option
allows the TRIG array to be stored in an external file, read
in and re-used without the need for a call with INIT equal
to 'I'. The routine carries out a simple test to check that
the current value of n is compatible with the array TRIG.
Constraint: INIT = 'I', 'S' or 'R'.
6: TRIG(2*N) -- DOUBLE PRECISION array Input/Output
On entry: if INIT = 'S' or 'R', TRIG must contain the
required coefficients calculated in a previous call of the
routine. Otherwise TRIG need not be set. On exit: TRIG
contains the required coefficients (computed by the routine
if INIT = 'I').
7: WORK(2*M*N) -- DOUBLE PRECISION array Workspace
8: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL= 1
On entry M < 1.
IFAIL= 2
On entry N < 1.
IFAIL= 3
On entry INIT is not one of 'I', 'S' or 'R'.
IFAIL= 4
On entry INIT = 'S', but none of C06FPF, C06FQF and C06FRF
has previously been called.
IFAIL= 5
On entry INIT = 'S' or 'R', but the array TRIG and the
current value of n are inconsistent.
7. Accuracy
Some indication of accuracy can be obtained by performing a
subsequent inverse transform and comparing the results with the
original sequence (in exact arithmetic they would be identical).
8. Further Comments
The time taken by the routine is approximately proportional to
nm*logn, but also depends on the factors of n. The routine is
fastest if the only prime factors of n are 2, 3 and 5, and is
particularly slow if n is a large prime, or has large prime
factors.
9. Example
This program reads in sequences of complex data values and prints
their discrete Fourier transforms (as computed by C06FRF).
Inverse transforms are then calculated using C06GCF and C06FRF
and printed out, showing that the original sequences are
restored.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06fuf}{NAG On-line Documentation: c06fuf}
\beginscroll
\begin{verbatim}
C06FUF(3NAG) Foundation Library (12/10/92) C06FUF(3NAG)
C06 -- Summation of Series C06FUF
C06FUF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06FUF computes the two-dimensional discrete Fourier transform of
a bivariate sequence of complex data values. This routine is
designed to be particularly efficient on vector processors.
2. Specification
SUBROUTINE C06FUF (M, N, X, Y, INIT, TRIGM, TRIGN, WORK,
1 IFAIL)
INTEGER M, N, IFAIL
DOUBLE PRECISION X(M*N), Y(M*N), TRIGM(2*M), TRIGN(2*N),
1 WORK(2*M*N)
CHARACTER*1 INIT
3. Description
This routine computes the two-dimensional discrete Fourier
transform of a bivariate sequence of complex data values z ,
j j
1 2
where j =0,1,...,m-1, j =0,1,...,n-1.
1 2
The discrete Fourier transform is here defined by:
m-1 n-1 ( ( j k j k ))
^ 1 -- -- ( ( 1 1 2 2))
z = ---- > > z *exp(-2(pi)i( ----+ ----)),
-- -- j j ( ( m n ))
k k \/mn j =0 j =0 1 2
1 2 1 2
where k =0,1,...,m-1, k =0,1,...,n-1.
1 2
1
(Note the scale factor of ---- in this definition.)
\/mn
To compute the inverse discrete Fourier transform, defined with
exp(+2(pi)i(...)) in the above formula instead of exp(-
2(pi)i(...)), this routine should be preceded and followed by
calls of C06GCF to form the complex conjugates of the data values
and the transform.
This routine calls C06FRF to perform multiple one-dimensional
discrete Fourier transforms by the fast Fourier transform (FFT)
algorithm in Brigham [1]. It is designed to be particularly
efficient on vector processors.
4. References
[1] Brigham E O (1973) The Fast Fourier Transform. Prentice-
Hall.
[2] Temperton C (1983) Self-sorting Mixed-radix Fast Fourier
Transforms. J. Comput. Phys. 52 1--23.
5. Parameters
1: M -- INTEGER Input
On entry: the number of rows, m, of the arrays X and Y.
Constraint: M >= 1.
2: N -- INTEGER Input
On entry: the number of columns, n, of the arrays X and Y.
Constraint: N >= 1.
3: X(M,N) -- DOUBLE PRECISION array Input/Output
4: Y(M,N) -- DOUBLE PRECISION array Input/Output
On entry: the real and imaginary parts of the complex data
values must be stored in arrays X and Y respectively. If X
and Y are regarded as two-dimensional arrays of dimension
(0:M-1,0:N-1), then X(j ,j ) and Y(j ,j ) must contain the
1 2 1 2
real and imaginary parts of z . On exit: the real and
j j
1 2
imaginary parts respectively of the corresponding elements
of the computed transform.
5: INIT -- CHARACTER*1 Input
On entry: if the trigonometric coefficients required to
compute the transforms are to be calculated by the routine
and stored in the arrays TRIGM and TRIGN, then INIT must be
set equal to 'I', (Initial call).
If INIT contains 'S', (Subsequent call), then the routine
assumes that trigonometric coefficients for the specified
values of m and n are supplied in the arrays TRIGM and
TRIGN, having been calculated in a previous call to the
routine.
If INIT contains 'R', (Restart), then the routine assumes
that trigonometric coefficients for the particular values of
m and n are supplied in the arrays TRIGM and TRIGN, but does
not check that the routine has previously been called. This
option allows the TRIGM and TRIGN arrays to be stored in an
external file, read in and re-used without the need for a
call with INIT equal to 'I'. The routine carries out a
simple test to check that the current values of m and n are
compatible with the arrays TRIGM and TRIGN. Constraint: INIT
= 'I', 'S' or 'R'.
6: TRIGM(2*M) -- DOUBLE PRECISION array Input/Output
7: TRIGN(2*N) -- DOUBLE PRECISION array Input/Output
On entry: if INIT = 'S' or 'R',TRIGM and TRIGN must contain
the required coefficients calculated in a previous call of
the routine. Otherwise TRIGM and TRIGN need not be set.
If m=n the same array may be supplied for TRIGM and TRIGN.
On exit: TRIGM and TRIGN contain the required coefficients
(computed by the routine if INIT = 'I').
8: WORK(2*M*N) -- DOUBLE PRECISION array Workspace
9: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL= 1
On entry M < 1.
IFAIL= 2
On entry N < 1.
IFAIL= 3
On entry INIT is not one of 'I', 'S' or 'R'.
IFAIL= 4
On entry INIT = 'S', but C06FUF has not previously been
called.
IFAIL= 5
On entry INIT = 'S' or 'R', but at least one of the arrays
TRIGM and TRIGN is inconsistent with the current value of M
or N.
7. Accuracy
Some indication of accuracy can be obtained by performing a
subsequent inverse transform and comparing the results with the
original sequence (in exact arithmetic they would be identical).
8. Further Comments
The time taken by the routine is approximately proportional to
mn*log(mn), but also depends on the factorization of the
individual dimensions m and n. The routine is somewhat faster
than average if their only prime factors are 2, 3 or 5; and
fastest of all if they are powers of 2.
9. Example
This program reads in a bivariate sequence of complex data values
and prints the two-dimensional Fourier transform. It then
performs an inverse transform and prints the sequence so
obtained, which may be compared to the original data values.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06gbf}{NAG On-line Documentation: c06gbf}
\beginscroll
\begin{verbatim}
C06GBF(3NAG) Foundation Library (12/10/92) C06GBF(3NAG)
C06 -- Summation of Series C06GBF
C06GBF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06GBF forms the complex conjugate of a Hermitian sequence of n
data values.
2. Specification
SUBROUTINE C06GBF (X, N, IFAIL)
INTEGER N, IFAIL
DOUBLE PRECISION X(N)
3. Description
This is a utility routine for use in conjunction with C06EAF,
C06EBF, C06FAF(*) or C06FBF(*) to calculate inverse discrete
Fourier transforms (see the Chapter Introduction).
4. References
None.
5. Parameters
1: X(N) -- DOUBLE PRECISION array Input/Output
On entry: if the data values z are written as x +iy and
j j j
if X is declared with bounds (0:N-1) in the (sub)program
from which C06GBF is called, then for 0<=j<=n/2, X(j) must
contain x (=x ), while for n/2<j<=n-1, X(j) must contain
j n-j
-y (=y ). In other words, X must contain the Hermitian
j n-j
sequence in Hermitian form. (See also Section 2.1.2 of the
Chapter Introduction). On exit: the imaginary parts y are
j
negated. The real parts x are not referenced.
j
2: N -- INTEGER Input
On entry: the number of data values, n. Constraint: N >= 1.
3: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
IFAIL= 1
N < 1.
7. Accuracy
Exact.
8. Further Comments
The time taken by the routine is negligible.
9. Example
This program reads in a sequence of real data values, calls
C06EAF followed by C06GBF to compute their inverse discrete
Fourier transform, and prints this after expanding it from
Hermitian form into a full complex sequence.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06gcf}{NAG On-line Documentation: c06gcf}
\beginscroll
\begin{verbatim}
C06GCF(3NAG) Foundation Library (12/10/92) C06GCF(3NAG)
C06 -- Summation of Series C06GCF
C06GCF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06GCF forms the complex conjugate of a sequence of n data
values.
2. Specification
SUBROUTINE C06GCF (Y, N, IFAIL)
INTEGER N, IFAIL
DOUBLE PRECISION Y(N)
3. Description
This is a utility routine for use in conjunction with C06ECF or
C06FCF(*) to calculate inverse discrete Fourier transforms (see
the Chapter Introduction).
4. References
None.
5. Parameters
1: Y(N) -- DOUBLE PRECISION array Input/Output
On entry: if Y is declared with bounds (0:N-1) in the (sub)
program which C06GCF is called, then Y(j) must contain the
imaginary part of the jth data value, for 0<=j<=n-1. On
exit: these values are negated.
2: N -- INTEGER Input
On entry: the number of data values, n. Constraint: N >= 1.
3: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
IFAIL= 1
N < 1.
7. Accuracy
Exact.
8. Further Comments
The time taken by the routine is negligible.
9. Example
This program reads in a sequence of complex data values and
prints their inverse discrete Fourier transform as computed by
calling C06GCF, followed by C06ECF and C06GCF again.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06gqf}{NAG On-line Documentation: c06gqf}
\beginscroll
\begin{verbatim}
C06GQF(3NAG) Foundation Library (12/10/92) C06GQF(3NAG)
C06 -- Summation of Series C06GQF
C06GQF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06GQF forms the complex conjugates of m Hermitian sequences,
each containing n data values.
2. Specification
SUBROUTINE C06GQF (M, N, X, IFAIL)
INTEGER M, N, IFAIL
DOUBLE PRECISION X(M*N)
3. Description
This is a utility routine for use in conjunction with C06FPF and
C06FQF to calculate inverse discrete Fourier transforms (see the
Chapter Introduction).
4. References
None.
5. Parameters
1: M -- INTEGER Input
On entry: the number of Hermitian sequences to be
conjugated, m. Constraint: M >= 1.
2: N -- INTEGER Input
On entry: the number of data values in each Hermitian
sequence, n. Constraint: N >= 1.
3: X(M,N) -- DOUBLE PRECISION array Input/Output
On entry: the data must be stored in array X as if in a
two-dimensional array of dimension (1:M,0:N-1); each of the
m sequences is stored in a row of the array in Hermitian
p p p
form. If the n data values z are written as x +iy , then
j j j
p
for 0<=j<=n/2, x is contained in X(p,j), and for 1<=j<=(n-
j
p
1)/2, y is contained in X(p,n-j). (See also Section 2.1.2
j
of the Chapter Introduction.) On exit: the imaginary parts
p p
y are negated. The real parts x are not referenced.
j j
4: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL= 1
On entry M < 1.
IFAIL= 2
On entry N < 1.
7. Accuracy
Exact.
8. Further Comments
None.
9. Example
This program reads in sequences of real data values which are
assumed to be Hermitian sequences of complex data stored in
Hermitian form. The sequences are expanded into full complex form
using C06GSF and printed. The sequences are then conjugated
(using C06GQF) and the conjugated sequences are expanded into
complex form using C06GSF and printed out.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
\begin{page}{manpageXXc06gsf}{NAG On-line Documentation: c06gsf}
\beginscroll
\begin{verbatim}
C06GSF(3NAG) Foundation Library (12/10/92) C06GSF(3NAG)
C06 -- Summation of Series C06GSF
C06GSF -- NAG Foundation Library Routine Document
Note: Before using this routine, please read the Users' Note for
your implementation to check implementation-dependent details.
The symbol (*) after a NAG routine name denotes a routine that is
not included in the Foundation Library.
1. Purpose
C06GSF takes m Hermitian sequences, each containing n data
values, and forms the real and imaginary parts of the m
corresponding complex sequences.
2. Specification
SUBROUTINE C06GSF (M, N, X, U, V, IFAIL)
INTEGER M, N, IFAIL
DOUBLE PRECISION X(M*N), U(M*N), V(M*N)
3. Description
This is a utility routine for use in conjunction with C06FPF and
C06FQF (see the Chapter Introduction).
4. References
None.
5. Parameters
1: M -- INTEGER Input
On entry: the number of Hermitian sequences, m, to be
converted into complex form. Constraint: M >= 1.
2: N -- INTEGER Input
On entry: the number of data values, n, in each sequence.
Constraint: N >= 1.
3: X(M,N) -- DOUBLE PRECISION array Input
On entry: the data must be stored in X as if in a two-
dimensional array of dimension (1:M,0:N-1); each of the m
sequences is stored in a row of the array in Hermitian form.
p p p
If the n data values z are written as x +iy , then for
j j j
p
0<=j<=n/2, x is contained in X(p,j), and for 1<=j<=(n-1)/2,
j
p
y is contained in X(p,n-j). (See also Section 2.1.2 of the
j
Chapter Introduction.)
4: U(M,N) -- DOUBLE PRECISION array Output
5: V(M,N) -- DOUBLE PRECISION array Output
On exit: the real and imaginary parts of the m sequences of
length n, are stored in U and V respectively, as if in two-
dimensional arrays of dimension (1:M,0:N-1); each of the m
sequences is stored as if in a row of each array. In other
words, if the real parts of the pth sequence are denoted by
p
x , for j=0,1,...,n-1 then the mn elements of the array U
j
contain the values
1 2 m 1 2 m 1 2 m
x ,x ,...,x , x ,x ,...,x ,..., x ,x ,...,x
0 0 0 1 1 1 n-1 n-1 n-1
6: IFAIL -- INTEGER Input/Output
On entry: IFAIL must be set to 0, -1 or 1. For users not
familiar with this parameter (described in the Essential
Introduction) the recommended value is 0.
On exit: IFAIL = 0 unless the routine detects an error (see
Section 6).
6. Error Indicators and Warnings
Errors detected by the routine:
If on entry IFAIL = 0 or -1, explanatory error messages are
output on the current error message unit (as defined by X04AAF).
IFAIL= 1
On entry M < 1.
IFAIL= 2
On entry N < 1.
7. Accuracy
Exact.
8. Further Comments
None.
9. Example
This program reads in sequences of real data values which are
assumed to be Hermitian sequences of complex data stored in
Hermitian form. The sequences are then expanded into full complex
form using C06GSF and printed.
The example program is not reproduced here. The source code for
all example programs is distributed with the NAG Foundation
Library software and should be available on-line.
\end{verbatim}
\endscroll
\end{page}
|