This file is indexed.

/usr/share/doc/maxima-doc/html/maxima_22.html is in maxima-doc 5.32.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on January, 10 2014 by texi2html 1.76 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people <dev@texi2html.cvshome.org>
Send bugs and suggestions to <users@texi2html.cvshome.org>

-->
<head>
<title>Maxima 5.32.1 Manual: 22. Numerical</title>

<meta name="description" content="Maxima 5.32.1 Manual: 22. Numerical">
<meta name="keywords" content="Maxima 5.32.1 Manual: 22. Numerical">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.76">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
body
{
    color: black;
    background: white; 
    margin-left: 8%;
    margin-right: 13%;
}

h1
{
    margin-left: +8%;
    font-size: 150%;
    font-family: sans-serif
}

h2
{
    font-size: 125%;
    font-family: sans-serif
}

h3
{
    font-size: 100%;
    font-family: sans-serif
}

h2,h3,h4,h5,h6 { margin-left: +4%; }

div.textbox
{
    border: solid;
    border-width: thin;
    /* width: 100%; */
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em
}

div.titlebox
{
    border: none;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em;
    background: rgb(200,255,255);
    font-family: sans-serif
}

div.synopsisbox
{
    border: none;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 2em;
    padding-right: 2em;
     background: rgb(255,220,255);
    /*background: rgb(200,255,255); */
    /* font-family: fixed */
}

pre.example
{
    border: 1px solid gray;
    padding-top: 1em;
    padding-bottom: 1em;
    padding-left: 1em;
    padding-right: 1em;
    /* background: rgb(247,242,180); */ /* kind of sandy */
    /* background: rgb(200,255,255); */ /* sky blue */
    background-color: #F1F5F9; /* light blue-gray */
    /* font-family: "Lucida Console", monospace */
}

div.spacerbox
{
    border: none;
    padding-top: 2em;
    padding-bottom: 2em
}

div.image
{
    margin: 0;
    padding: 1em;
    text-align: center;
}

div.categorybox
{
    border: 1px solid gray;
    padding-top: 0px;
    padding-bottom: 0px;
    padding-left: 1em;
    padding-right: 1em;
    background: rgb(247,242,220);
}


-->
</style>

<link rel="icon" href="http://maxima.sourceforge.net/favicon.ico"/>
</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Numerical"></a>
<a name="SEC107"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="maxima_21.html#SEC106" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC108" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima_21.html#SEC104" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_23.html#SEC113" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h1 class="chapter"> 22. Numerical </h1>

<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#SEC108">22.1 Introduction to fast Fourier transform</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">                     
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC109">22.2 Functions and Variables for fast Fourier transform</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC110">22.3 Functions for numerical solution of equations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC111">22.4 Introduction to numerical solution of differential equations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC112">22.5 Functions for numerical solution of differential equations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>

<p><a name="Item_003a-Introduction-to-fast-Fourier-transform"></a>
</p><hr size="6">
<a name="Introduction-to-fast-Fourier-transform"></a>
<a name="SEC108"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC107" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC109" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC107" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC107" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_23.html#SEC113" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 22.1 Introduction to fast Fourier transform </h2>

<p>The <code>fft</code> package comprises functions for the numerical (not symbolic)
computation of the fast Fourier transform.
</p>
<div class=categorybox>
&middot;
<p>@ref{Category: Fourier transform} &middot;
@ref{Category: Numerical methods} &middot;
@ref{Category: Share packages} &middot;
@ref{Category: Package fft}
</div>
</p>

<p><a name="Item_003a-Functions-and-Variables-for-fast-Fourier-transform"></a>
</p><hr size="6">
<a name="Functions-and-Variables-for-fast-Fourier-transform"></a>
<a name="SEC109"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC108" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC110" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC107" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC107" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_23.html#SEC113" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 22.2 Functions and Variables for fast Fourier transform </h2>

<p><a name="polartorect"></a>
<a name="Item_003a-polartorect"></a>
</p><dl>
<dt><u>Function:</u> <b>polartorect</b><i> (<var>r</var>, <var>t</var>)</i>
<a name="IDX932"></a>
</dt>
<dd><p>Translates complex values of the form <code>r %e^(%i t)</code> to the form
<code>a + b %i</code>, where <var>r</var> is the magnitude and <var>t</var> is the phase.
<var>r</var> and <var>t</var> are 1-dimensional arrays of the same size.
The array size need not be a power of 2.
</p>
<p>The original values of the input arrays are
replaced by the real and imaginary parts, <code>a</code> and <code>b</code>, on return.
The outputs are calculated as
</p>
<pre class="example">a = r cos(t)
b = r sin(t)
</pre>
<p><code>polartorect</code> is the inverse function of <code>recttopolar</code>.
</p>
<p><code>load(fft)</code> loads this function.  See also <code>fft</code>.
</p>
<div class=categorybox>
&middot;
<p>@ref{Category: Package fft} &middot;
@ref{Category: Complex variables}
</div>
</p></dd></dl>

<p><a name="recttopolar"></a>
<a name="Item_003a-recttopolar"></a>
</p><dl>
<dt><u>Function:</u> <b>recttopolar</b><i> (<var>a</var>, <var>b</var>)</i>
<a name="IDX933"></a>
</dt>
<dd><p>Translates complex values of the form <code>a + b %i</code> to the form
<code>r %e^(%i t)</code>, where <var>a</var> is the real part and <var>b</var> is the imaginary
part.  <var>a</var> and <var>b</var> are 1-dimensional arrays of the same size.
The array size need not be a power of 2.
</p>
<p>The original values of the input arrays are
replaced by the magnitude and angle, <code>r</code> and <code>t</code>, on return.
The outputs are calculated as
</p>
<pre class="example">r = sqrt(a^2 + b^2)
t = atan2(b, a)
</pre>
<p>The computed angle is in the range <code>-%pi</code> to <code>%pi</code>.
</p>
<p><code>recttopolar</code> is the inverse function of <code>polartorect</code>.
</p>
<p><code>load(fft)</code> loads this function.  See also <code>fft</code>.
</p>
<div class=categorybox>
&middot;
<p>@ref{Category: Package fft} &middot;
@ref{Category: Complex variables}
</div>
</p></dd></dl>

<p><a name="inverse_005ffft"></a>
<a name="Item_003a-inverse_005ffft"></a>
</p><dl>
<dt><u>Function:</u> <b>inverse_fft</b><i> (<var>y</var>)</i>
<a name="IDX934"></a>
</dt>
<dd><p>Computes the inverse complex fast Fourier transform.
<var>y</var> is a list or array (named or unnamed) which contains the data to
transform.  The number of elements must be a power of 2.
The elements must be literal numbers (integers, rationals, floats, or bigfloats)
or symbolic constants,
or expressions <code>a + b*%i</code> where <code>a</code> and <code>b</code> are literal numbers
or symbolic constants.
</p>
<p><code>inverse_fft</code> returns a new object of the same type as <var>y</var>,
which is not modified.
Results are always computed as floats
or expressions <code>a + b*%i</code> where <code>a</code> and <code>b</code> are floats.
</p>
<p>The inverse discrete Fourier transform is defined as follows.
Let <code>x</code> be the output of the inverse transform.
Then for <code>j</code> from 0 through <code>n - 1</code>,
</p>
<pre class="example">x[j] = sum(y[k] exp(-2 %i %pi j k / n), k, 0, n - 1)
</pre>
<p><code>load(fft)</code> loads this function.
</p>
<p>See also <code>fft</code> (forward transform), <code>recttopolar</code>, and
<code>polartorect</code>.
</p>
<p>Examples:
</p>
<p>Real data.
</p>
<pre class="example">(%i1) load (fft) $
(%i2) fpprintprec : 4 $
(%i3) L : [1, 2, 3, 4, -1, -2, -3, -4] $
(%i4) L1 : inverse_fft (L);
(%o4) [0.0, 14.49 %i - .8284, 0.0, 2.485 %i + 4.828, 0.0, 
                       4.828 - 2.485 %i, 0.0, - 14.49 %i - .8284]
(%i5) L2 : fft (L1);
(%o5) [1.0, 2.0 - 2.168L-19 %i, 3.0 - 7.525L-20 %i, 
4.0 - 4.256L-19 %i, - 1.0, 2.168L-19 %i - 2.0, 
7.525L-20 %i - 3.0, 4.256L-19 %i - 4.0]
(%i6) lmax (abs (L2 - L));
(%o6)                       3.545L-16
</pre>
<p>Complex data.
</p>
<pre class="example">(%i1) load (fft) $
(%i2) fpprintprec : 4 $                 
(%i3) L : [1, 1 + %i, 1 - %i, -1, -1, 1 - %i, 1 + %i, 1] $
(%i4) L1 : inverse_fft (L);
(%o4) [4.0, 2.711L-19 %i + 4.0, 2.0 %i - 2.0, 
- 2.828 %i - 2.828, 0.0, 5.421L-20 %i + 4.0, - 2.0 %i - 2.0, 
2.828 %i + 2.828]
(%i5) L2 : fft (L1);
(%o5) [4.066E-20 %i + 1.0, 1.0 %i + 1.0, 1.0 - 1.0 %i, 
1.55L-19 %i - 1.0, - 4.066E-20 %i - 1.0, 1.0 - 1.0 %i, 
1.0 %i + 1.0, 1.0 - 7.368L-20 %i]
(%i6) lmax (abs (L2 - L));                    
(%o6)                       6.841L-17
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Package fft}
</div>
</p></dd></dl>

<p><a name="fft"></a>
<a name="Item_003a-fft"></a>
</p><dl>
<dt><u>Function:</u> <b>fft</b><i> (<var>x</var>)</i>
<a name="IDX935"></a>
</dt>
<dd><p>Computes the complex fast Fourier transform.
<var>x</var> is a list or array (named or unnamed) which contains the data to
transform.  The number of elements must be a power of 2.
The elements must be literal numbers (integers, rationals, floats, or bigfloats)
or symbolic constants,
or expressions <code>a + b*%i</code> where <code>a</code> and <code>b</code> are literal numbers
or symbolic constants.
</p>
<p><code>fft</code> returns a new object of the same type as <var>x</var>,
which is not modified.
Results are always computed as floats
or expressions <code>a + b*%i</code> where <code>a</code> and <code>b</code> are floats.
</p>
<p>The discrete Fourier transform is defined as follows.
Let <code>y</code> be the output of the transform.
Then for <code>k</code> from 0 through <code>n - 1</code>,
</p>
<pre class="example">y[k] = (1/n) sum(x[j] exp(+2 %i %pi j k / n), j, 0, n - 1)
</pre>
<p>When the data <var>x</var> are real,
real coefficients <code>a</code> and <code>b</code> can be computed such that
</p>
<pre class="example">x[j] = sum(a[k]*cos(2*%pi*j*k/n)+b[k]*sin(2*%pi*j*k/n), k, 0, n/2)
</pre>
<p>with
</p>
<pre class="example">a[0] = realpart (y[0])
b[0] = 0
</pre>
<p>and, for k from 1 through n/2 - 1,
</p>
<pre class="example">a[k] = realpart (y[k] + y[n - k])
b[k] = imagpart (y[n - k] - y[k])
</pre>
<p>and
</p>
<pre class="example">a[n/2] = realpart (y[n/2])
b[n/2] = 0
</pre>
<p><code>load(fft)</code> loads this function.
</p>
<p>See also <code>inverse_fft</code> (inverse transform), <code>recttopolar</code>, and
<code>polartorect</code>.
</p>
<p>Examples:
</p>
<p>Real data.
</p>
<pre class="example">(%i1) load (fft) $
(%i2) fpprintprec : 4 $
(%i3) L : [1, 2, 3, 4, -1, -2, -3, -4] $
(%i4) L1 : fft (L);
(%o4) [0.0, - 1.811 %i - .1036, 0.0, .6036 - .3107 %i, 0.0, 
                         .3107 %i + .6036, 0.0, 1.811 %i - .1036]
(%i5) L2 : inverse_fft (L1);
(%o5) [1.0, 2.168L-19 %i + 2.0, 7.525L-20 %i + 3.0, 
4.256L-19 %i + 4.0, - 1.0, - 2.168L-19 %i - 2.0, 
- 7.525L-20 %i - 3.0, - 4.256L-19 %i - 4.0]
(%i6) lmax (abs (L2 - L));
(%o6)                       3.545L-16
</pre>
<p>Complex data.
</p>
<pre class="example">(%i1) load (fft) $
(%i2) fpprintprec : 4 $
(%i3) L : [1, 1 + %i, 1 - %i, -1, -1, 1 - %i, 1 + %i, 1] $
(%i4) L1 : fft (L);
(%o4) [0.5, .3536 %i + .3536, - 0.25 %i - 0.25, 
0.5 - 6.776L-21 %i, 0.0, - .3536 %i - .3536, 0.25 %i - 0.25, 
0.5 - 3.388L-20 %i]
(%i5) L2 : inverse_fft (L1);
(%o5) [1.0 - 4.066E-20 %i, 1.0 %i + 1.0, 1.0 - 1.0 %i, 
- 1.008L-19 %i - 1.0, 4.066E-20 %i - 1.0, 1.0 - 1.0 %i, 
1.0 %i + 1.0, 1.947L-20 %i + 1.0]
(%i6) lmax (abs (L2 - L));
(%o6)                       6.83L-17
</pre>
<p>Computation of sine and cosine coefficients.
</p>
<pre class="example">(%i1) load (fft) $
(%i2) fpprintprec : 4 $
(%i3) L : [1, 2, 3, 4, 5, 6, 7, 8] $
(%i4) n : length (L) $
(%i5) x : make_array (any, n) $
(%i6) fillarray (x, L) $
(%i7) y : fft (x) $
(%i8) a : make_array (any, n/2 + 1) $
(%i9) b : make_array (any, n/2 + 1) $
(%i10) a[0] : realpart (y[0]) $
(%i11) b[0] : 0 $
(%i12) for k : 1 thru n/2 - 1 do
   (a[k] : realpart (y[k] + y[n - k]),
    b[k] : imagpart (y[n - k] - y[k]));
(%o12)                        done
(%i13) a[n/2] : y[n/2] $
(%i14) b[n/2] : 0 $
(%i15) listarray (a);
(%o15)          [4.5, - 1.0, - 1.0, - 1.0, - 0.5]
(%i16) listarray (b);
(%o16)           [0, - 2.414, - 1.0, - .4142, 0]
(%i17) f(j) := sum (a[k]*cos(2*%pi*j*k/n) + b[k]*sin(2*%pi*j*k/n), 
                    k, 0, n/2) $
(%i18) makelist (float (f (j)), j, 0, n - 1);
(%o18)      [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Package fft}
</div>
</p></dd></dl>

<p><a name="Item_003a-Functions-for-numerical-solution-of-equations"></a>
</p><hr size="6">
<a name="Functions-for-numerical-solution-of-equations"></a>
<a name="SEC110"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC109" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC111" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC107" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC107" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_23.html#SEC113" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 22.3 Functions for numerical solution of equations </h2>

<p><a name="horner"></a>
<a name="Item_003a-horner"></a>
</p><dl>
<dt><u>Function:</u> <b>horner</b><i> (<var>expr</var>, <var>x</var>)</i>
<a name="IDX936"></a>
</dt>
<dt><u>Function:</u> <b>horner</b><i> (<var>expr</var>)</i>
<a name="IDX937"></a>
</dt>
<dd><p>Returns a rearranged representation of <var>expr</var> as in Horner's rule, using
<var>x</var> as the main variable if it is specified.  <code>x</code> may be omitted in
which case the main variable of the canonical rational expression form of
<var>expr</var> is used.
</p>
<p><code>horner</code> sometimes improves stability if <code>expr</code> is
to be numerically evaluated.  It is also useful if Maxima is used to
generate programs to be run in Fortran.  See also <code>stringout</code>.
</p>
<pre class="example">(%i1) expr: 1e-155*x^2 - 5.5*x + 5.2e155;
                           2
(%o1)             1.e-155 x  - 5.5 x + 5.2e+155
(%i2) expr2: horner (%, x), keepfloat: true;
(%o2)         1.0 ((1.e-155 x - 5.5) x + 5.2e+155)
(%i3) ev (expr, x=1e155);
Maxima encountered a Lisp error:

 arithmetic error FLOATING-POINT-OVERFLOW signalled

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
(%i4) ev (expr2, x=1e155);
(%o4)                 7.00000000000001e+154
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Numerical methods}
</div>
</p></dd></dl>

<p><a name="find_005froot"></a>
<a name="bf_005ffind_005froot"></a>
<a name="find_005froot_005ferror"></a>
<a name="find_005froot_005fabs"></a>
<a name="find_005froot_005frel"></a>
<a name="Item_003a-find_005froot"></a>
</p><dl>
<dt><u>Function:</u> <b>find_root</b><i> (<var>expr</var>, <var>x</var>, <var>a</var>, <var>b</var>, [<var>abserr</var>, <var>relerr</var>])</i>
<a name="IDX938"></a>
</dt>
<dt><u>Function:</u> <b>find_root</b><i> (<var>f</var>, <var>a</var>, <var>b</var>, [<var>abserr</var>, <var>relerr</var>])</i>
<a name="IDX939"></a>
</dt>
<dt><u>Function:</u> <b>bf_find_root</b><i> (<var>expr</var>, <var>x</var>, <var>a</var>, <var>b</var>, [<var>abserr</var>, <var>relerr</var>])</i>
<a name="IDX940"></a>
</dt>
<dt><u>Function:</u> <b>bf_find_root</b><i> (<var>f</var>, <var>a</var>, <var>b</var>, [<var>abserr</var>, <var>relerr</var>])</i>
<a name="IDX941"></a>
</dt>
<dt><u>Option variable:</u> <b>find_root_error</b>
<a name="IDX942"></a>
</dt>
<dt><u>Option variable:</u> <b>find_root_abs</b>
<a name="IDX943"></a>
</dt>
<dt><u>Option variable:</u> <b>find_root_rel</b>
<a name="IDX944"></a>
</dt>
<dd><p>Finds a root of the expression <var>expr</var> or the function <var>f</var> over the
closed interval <em>[<var>a</var>, <var>b</var>]</em>.  The expression <var>expr</var> may be an
equation, in which case <code>find_root</code> seeks a root of
<code>lhs(<var>expr</var>) - rhs(<var>expr</var>)</code>.
</p>
<p>Given that Maxima can evaluate <var>expr</var> or <var>f</var> over
<em>[<var>a</var>, <var>b</var>]</em> and that <var>expr</var> or <var>f</var> is continuous,
<code>find_root</code> is guaranteed to find the root,
or one of the roots if there is more than one.
</p>
<p><code>find_root</code> initially applies binary search.
If the function in question appears to be smooth enough,
<code>find_root</code> applies linear interpolation instead.
</p>
<p><code>bf_find_root</code> is a bigfloat version of <code>find_root</code>.  The
function is computed using bigfloat arithmetic and a bigfloat result
is returned.  Otherwise, <code>bf_find_root</code> is identical to
<code>find_root</code>, and the following description is equally applicable
to <code>bf_find_root</code>.
</p>
<p>The accuracy of <code>find_root</code> is governed by <code>abserr</code> and
<code>relerr</code>, which are optional keyword arguments to
<code>find_root</code>.  These keyword arguments take the form
<code>key=val</code>.  The keyword arguments are
</p>
<dl compact="compact">
<dt> <code>abserr</code></dt>
<dd><p>Desired absolute error of function value at root.  Default is
<code>find_root_abs</code>.
</p></dd>
<dt> <code>relerr</code></dt>
<dd><p>Desired relative error of root.  Default is <code>find_root_rel</code>.
</p></dd>
</dl>

<p><code>find_root</code> stops when the function in question evaluates to
something less than or equal to <code>abserr</code>, or if successive
approximants <var>x_0</var>, <var>x_1</var> differ by no more than <code>relerr
* max(abs(x_0), abs(x_1))</code>.  The default values of
<code>find_root_abs</code> and <code>find_root_rel</code> are both zero.
</p>
<p><code>find_root</code> expects the function in question to have a different sign at
the endpoints of the search interval.
When the function evaluates to a number at both endpoints
and these numbers have the same sign,
the behavior of <code>find_root</code> is governed by <code>find_root_error</code>.
When <code>find_root_error</code> is <code>true</code>,
<code>find_root</code> prints an error message.
Otherwise <code>find_root</code> returns the value of <code>find_root_error</code>.
The default value of <code>find_root_error</code> is <code>true</code>.
</p>
<p>If <var>f</var> evaluates to something other than a number at any step in the search
algorithm, <code>find_root</code> returns a partially-evaluated <code>find_root</code>
expression.
</p>
<p>The order of <var>a</var> and <var>b</var> is ignored; the region in which a root is
sought is <em>[min(<var>a</var>, <var>b</var>), max(<var>a</var>, <var>b</var>)]</em>.
</p>
<p>Examples:
</p>

<pre class="example">(%i1) f(x) := sin(x) - x/2;
                                        x
(%o1)                  f(x) := sin(x) - -
                                        2
(%i2) find_root (sin(x) - x/2, x, 0.1, %pi);
(%o2)                   1.895494267033981
(%i3) find_root (sin(x) = x/2, x, 0.1, %pi);
(%o3)                   1.895494267033981
(%i4) find_root (f(x), x, 0.1, %pi);
(%o4)                   1.895494267033981
(%i5) find_root (f, 0.1, %pi);
(%o5)                   1.895494267033981
(%i6) find_root (exp(x) = y, x, 0, 100);
                            x
(%o6)           find_root(%e  = y, x, 0.0, 100.0)
(%i7) find_root (exp(x) = y, x, 0, 100), y = 10;
(%o7)                   2.302585092994046
(%i8) log (10.0);
(%o8)                   2.302585092994046
(%i9) fpprec:32;
(%o9)                           32
(%i10) bf_find_root (exp(x) = y, x, 0, 100), y = 10;
(%o10)                  2.3025850929940456840179914546844b0
(%i11) log(10b0);
(%o11)                  2.3025850929940456840179914546844b0
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Algebraic equations} &middot;
@ref{Category: Numerical methods}
</div>
</p></dd></dl>

<p><a name="newton"></a>
<a name="Item_003a-newton"></a>
</p><dl>
<dt><u>Function:</u> <b>newton</b><i> (<var>expr</var>, <var>x</var>, <var>x_0</var>, <var>eps</var>)</i>
<a name="IDX945"></a>
</dt>
<dd><p>Returns an approximate solution of <code><var>expr</var> = 0</code> by Newton's method,
considering <var>expr</var> to be a function of one variable, <var>x</var>.
The search begins with <code><var>x</var> = <var>x_0</var></code>
and proceeds until <code>abs(<var>expr</var>) &lt; <var>eps</var></code>
(with <var>expr</var> evaluated at the current value of <var>x</var>).
</p>
<p><code>newton</code> allows undefined variables to appear in <var>expr</var>,
so long as the termination test <code>abs(<var>expr</var>) &lt; <var>eps</var></code> evaluates
to <code>true</code> or <code>false</code>.
Thus it is not necessary that <var>expr</var> evaluate to a number.
</p>
<p><code>load(newton1)</code> loads this function.
</p>
<p>See also <code>realroots</code>, <code>allroots</code>, <code>find_root</code>, and
<code>mnewton</code>.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) load (newton1);
(%o1)  /maxima/share/numeric/newton1.mac
(%i2) newton (cos (u), u, 1, 1/100);
(%o2)                   1.570675277161251
(%i3) ev (cos (u), u = %);
(%o3)                 1.2104963335033529e-4
(%i4) assume (a &gt; 0);
(%o4)                        [a &gt; 0]
(%i5) newton (x^2 - a^2, x, a/2, a^2/100);
(%o5)                  1.00030487804878 a
(%i6) ev (x^2 - a^2, x = %);
                                           2
(%o6)                6.098490481853958e-4 a
</pre>
<div class=categorybox>
&middot;
<p>@ref{Category: Algebraic equations} &middot;
@ref{Category: Numerical methods}
</div>
</p></dd></dl>

<p><a name="Item_003a-Introduction-to-numerical-solution-of-differential-equations"></a>
</p><hr size="6">
<a name="Introduction-to-numerical-solution-of-differential-equations"></a>
<a name="SEC111"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC110" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC112" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC107" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC107" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_23.html#SEC113" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 22.4 Introduction to numerical solution of differential equations </h2>

<p>The Ordinary Differential Equations (ODE) solved by the functions in this
section should have the form,
</p><pre class="example">       dy
       -- = F(x,y)
       dx
</pre><p>which is a first-order ODE. Higher order differential equations of order
<var>n</var> must be written as a system of <var>n</var> first-order equations of that
kind. For instance, a second-order ODE should be written as a system of two
equations
</p><pre class="example">       dx               dy
       -- = G(x,y,t)    -- = F(x,y,t) 
       dt               dt
</pre>
<p>The first argument in the functions will be a list with the expressions on
the right-side of the ODE's. The variables whose derivatives are represented
by those expressions should be given in a second list. In the case above those
variables are <var>x</var> and <var>y</var>. The independent variable, <var>t</var> in the
examples above, might be given in a separated option. If the expressions
given do not depend on that independent variable, the system is called
autonomous.
</p>
<div class=categorybox>
&middot;
<p>@ref{Category: Differential equations} &middot;
@ref{Category: Numerical methods} &middot;
@ref{Category: Plotting}
</div>
</p>

<p><a name="Item_003a-Functions-for-numerical-solution-of-differential-equations"></a>
</p><hr size="6">
<a name="Functions-for-numerical-solution-of-differential-equations"></a>
<a name="SEC112"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC111" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima_23.html#SEC113" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC107" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SEC107" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_23.html#SEC113" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 22.5 Functions for numerical solution of differential equations </h2>
<p><a name="Item_003a-plotdf"></a>
</p><dl>
<dt><u>Function:</u> <b>plotdf</b><i> (<var>dydx</var>, ...options...)</i>
<a name="IDX946"></a>
</dt>
<dt><u>Function:</u> <b>plotdf</b><i> (<var>dvdu</var>, <code>[</code><var>u</var>,<var>v</var><code>]</code>, ...options...)</i>
<a name="IDX947"></a>
</dt>
<dt><u>Function:</u> <b>plotdf</b><i> (<code>[</code><var>dxdt</var>,<var>dydt</var><code>]</code>, ...options...)</i>
<a name="IDX948"></a>
</dt>
<dt><u>Function:</u> <b>plotdf</b><i> (<code>[</code><var>dudt</var>,<var>dvdt</var><code>]</code>, <code>[</code><var>u</var>,<var>v</var><code>]</code>, ...options...)</i>
<a name="IDX949"></a>
</dt>
<dd><p>The function <code>plotdf</code> creates a two-dimensional plot of the direction
field (also called slope field) for a first-order Ordinary Differential
Equation (ODE) or a system of two autonomous first-order ODE's.
</p>
<p>Plotdf requires Xmaxima, even if its run from a Maxima session in
a console, since the plot will be created by the Tk scripts in Xmaxima.
If Xmaxima is not installed plotdf will not work.
</p>
<p><var>dydx</var>, <var>dxdt</var> and <var>dydt</var> are expressions that depend on
<var>x</var> and <var>y</var>. <var>dvdu</var>, <var>dudt</var> and <var>dvdt</var> are
expressions that depend on <var>u</var> and <var>v</var>. In addition to those two
variables, the expressions can also depend on a set of parameters, with
numerical values given with the <code>parameters</code> option (the option
syntax is given below), or with a range of allowed values specified by a
<var>sliders</var> option.
</p>
<p>Several other options can be given within the command, or selected in
the menu. Integral curves can be obtained by clicking on the plot, or
with the option <code>trajectory_at</code>. The direction of the integration
can be controlled with the <code>direction</code> option, which can have
values of <em>forward</em>, <em>backward</em> or <em>both</em>. The number of
integration steps is given by <code>nsteps</code>; at each integration
step the time increment will be adjusted automatically to produce
displacements much smaller than the size of the plot window. The
numerical method used is 4th order Runge-Kutta with variable time steps.
</p>
<p><b>Plot window menu:</b>
</p>
<p>The menu bar of the plot window has the following seven icons:
</p>
<p>An X. Can be used to close the plot window.
</p>
<p>A wrench and a screwdriver. Opens the configuration menu with several
fields that show the ODE(s) in use and various other settings. If a pair
of coordinates are entered in the field <em>Trajectory at</em> and the
<kbd>enter</kbd> key is pressed, a new integral curve will be shown, in
addition to the ones already shown.
</p>
<p>Two arrows following a circle. Replots the direction field with the
new settings defined in the configuration menu and replots only the last
integral curve that was previously plotted.
</p>
<p>Hard disk drive with an arrow. Used to save a copy of the
plot, in Postscript format, in the file specified in a field of the
box that appears when that icon is clicked.
</p>
<p>Magnifying glass with a plus sign. Zooms in the plot.
</p>
<p>Magnifying glass with a minus sign. Zooms out the plot. The plot can be
displaced by holding down the right mouse button while the mouse is
moved.
</p>
<p>Icon of a plot. Opens another window with a plot of the two variables
in terms of time, for the last integral curve that was plotted.
</p>
<p><b>Plot options:</b>
</p>
<p>Options can also be given within the <code>plotdf</code> itself, each one being
a list of two or more elements. The first element in each option is the name
of the option, and the remainder is the value or values assigned to the
option.
</p>
<p>The options which are recognized by <code>plotdf</code> are the following:
</p>
<ul>
<li>
<em>nsteps</em> defines the number of steps that will be used for the
independent variable, to compute an integral curve. The default value is
100.

</li><li>
<em>direction</em> defines the direction of the independent
variable that will be followed to compute an integral curve. Possible
values are <code>forward</code>, to make the independent variable increase
<code>nsteps</code> times, with increments <code>tstep</code>, <code>backward</code>, to
make the independent variable decrease, or <code>both</code> that will lead to
an integral curve that extends <code>nsteps</code> forward, and <code>nsteps</code>
backward. The keywords <code>right</code> and <code>left</code> can be used as
synonyms for <code>forward</code> and <code>backward</code>.
The default value is <code>both</code>.

</li><li>
<em>tinitial</em> defines the initial value of variable <var>t</var> used
to compute integral curves. Since the differential equations are
autonomous, that setting will only appear in the plot of the curves as
functions of <var>t</var>. 
The default value is 0.

</li><li>
<em>versus_t</em> is used to create a second plot window, with a
plot of an integral curve, as two functions <var>x</var>, <var>y</var>, of the
independent variable <var>t</var>. If <code>versus_t</code> is given any value
different from 0, the second plot window will be displayed. The second
plot window includes another menu, similar to the menu of the main plot
window.
The default value is 0.

</li><li>
<em>trajectory_at</em> defines the coordinates <var>xinitial</var> and
<var>yinitial</var> for the starting point of an integral curve.
The option is empty by default.

</li><li>
<em>parameters</em> defines a list of parameters, and their
numerical values, used in the definition of the differential
equations. The name and values of the parameters must be given in a
string with a comma-separated sequence of pairs <code>name=value</code>.

</li><li>
<em>sliders</em> defines a list of parameters that will be changed
interactively using slider buttons, and the range of variation of those
parameters. The names and ranges of the parameters must be given in a
string with a comma-separated sequence of elements <code>name=min:max</code>

</li><li>
<em>xfun</em> defines a string with semi-colon-separated sequence
of functions of <var>x</var> to be displayed, on top of the direction field.
Those functions will be parsed by Tcl and not by Maxima.

</li><li>
<em>x</em> should be followed by two numbers, which will set up the minimum
and maximum values shown on the horizontal axis. If the variable on the
horizontal axis is not <var>x</var>, then this option should have the name of
the variable on the horizontal axis.
The default horizontal range is from -10 to 10.

</li><li>
<em>y</em> should be followed by two numbers, which will set up the minimum
and maximum values shown on the vertical axis. If the variable on the
vertical axis is not <var>y</var>, then this option should have the name of
the variable on the vertical axis.
The default vertical range is from -10 to 10.

</li><li>
<em>xaxislabel</em> will be used to identify the horizontal axis. Its default value is the name of the first state variable.

</li><li>
<em>yaxislabel</em> will be used to identify the vertical axis. Its default value is the name of the second state variable.

</li></ul>

<p><strong>Examples:</strong>
</p>
<ul>
<li>
To show the direction field of the differential equation <em>y' = exp(-x) + y</em> and the solution that goes through <em>(2, -0.1)</em>:
<pre class="example">(%i1) plotdf(exp(-x)+y,[trajectory_at,2,-0.1])$
</pre>
<p><div class="image"><img src="./figures/plotdf1.gif" alt="figures/plotdf1"></div>
</p>
</li><li>
To obtain the direction field for the equation <em>diff(y,x) = x - y^2</em> and the solution with initial condition <em>y(-1) = 3</em>, we can use the command:
<pre class="example">(%i1) plotdf(x-y^2,[xfun,&quot;sqrt(x);-sqrt(x)&quot;],
         [trajectory_at,-1,3], [direction,forward],
         [y,-5,5], [x,-4,16])$
</pre>
<p>The graph also shows the function <em>y = sqrt(x)</em>. 
</p>
<p><div class="image"><img src="./figures/plotdf2.gif" alt="figures/plotdf2"></div>
</p>
</li><li>
The following example shows the direction field of a harmonic oscillator,
defined by the two equations <em>dz/dt = v</em> and <em>dv/dt = -k*z/m</em>,
and the integral curve through <em>(z,v) = (6,0)</em>, with a slider that
will allow you to change the value of <em>m</em> interactively (<em>k</em> is
fixed at 2):
<pre class="example">(%i1) plotdf([v,-k*z/m], [z,v], [parameters,&quot;m=2,k=2&quot;],
           [sliders,&quot;m=1:5&quot;], [trajectory_at,6,0])$
</pre>
<p><div class="image"><img src="./figures/plotdf3.gif" alt="figures/plotdf3"></div>
</p>
</li><li>
To plot the direction field of the Duffing equation, <em>m*x&quot;+c*x'+k*x+b*x^3 = 0</em>, we introduce the variable <em>y=x'</em> and use:
<pre class="example">(%i1) plotdf([y,-(k*x + c*y + b*x^3)/m],
             [parameters,&quot;k=-1,m=1.0,c=0,b=1&quot;],
             [sliders,&quot;k=-2:2,m=-1:1&quot;],[tstep,0.1])$
</pre>
<p><div class="image"><img src="./figures/plotdf4.gif" alt="figures/plotdf4"></div>
</p>
</li><li>
The direction field for a damped pendulum, including the
solution for the given initial conditions, with a slider that
can be used to change the value of the mass <em>m</em>, and with a plot of
the two state variables as a function of time:

<pre class="example">(%i1) plotdf([w,-g*sin(a)/l - b*w/m/l], [a,w],
        [parameters,&quot;g=9.8,l=0.5,m=0.3,b=0.05&quot;],
        [trajectory_at,1.05,-9],[tstep,0.01],
        [a,-10,2], [w,-14,14], [direction,forward],
        [nsteps,300], [sliders,&quot;m=0.1:1&quot;], [versus_t,1])$
</pre>
<p><div class="image"><img src="./figures/plotdf5.gif" alt="figures/plotdf5"></div><div class="image"><img src="./figures/plotdf6.gif" alt="figures/plotdf6"></div>
</p>
</li></ul>

<div class=categorybox>
&middot;
<p>@ref{Category: Differential equations} &middot;
@ref{Category: Plotting} &middot;
@ref{Category: Numerical methods}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-ploteq"></a>
</p><dl>
<dt><u>Function:</u> <b>ploteq</b><i> (<var>exp</var>, ...options...)</i>
<a name="IDX950"></a>
</dt>
<dd><p>Plots equipotential curves for <var>exp</var>, which should be an expression
depending on two variables. The curves are obtained by integrating the
differential equation that define the orthogonal trajectories to the solutions
of the autonomous system obtained from the gradient of the expression given.
The plot can also show the integral curves for that gradient system (option
fieldlines).
</p>
<p>This program also requires Xmaxima, even if its run from a Maxima session in
a console, since the plot will be created by the Tk scripts in Xmaxima.
By default, the plot region will be empty until the user clicks in a point
(or gives its coordinate with in the set-up menu or via the trajectory_at option).
</p>
<p>Most options accepted by plotdf can also be used for ploteq and the plot
interface is the same that was described in plotdf.
</p>
<p>Example:
</p>
<pre class="example">(%i1) V: 900/((x+1)^2+y^2)^(1/2)-900/((x-1)^2+y^2)^(1/2)$
(%i2) ploteq(V,[x,-2,2],[y,-2,2],[fieldlines,&quot;blue&quot;])$
</pre>
<p>Clicking on a point will plot the equipotential curve that passes by that point
(in red) and the orthogonal trajectory (in blue).
</p>
<div class=categorybox>
&middot;
<p>@ref{Category: Differential equations} &middot;
@ref{Category: Plotting} &middot;
@ref{Category: Numerical methods}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-rk"></a>
</p><dl>
<dt><u>Function:</u> <b>rk</b><i> (<var>ODE</var>, <var>var</var>, <var>initial</var>, <var>domain</var>)</i>
<a name="IDX951"></a>
</dt>
<dt><u>Function:</u> <b>rk</b><i> ([<var>ODE1</var>,...,<var>ODEm</var>], [<var>v1</var>,...,<var>vm</var>], [<var>init1</var>,...,<var>initm</var>], <var>domain</var>)</i>
<a name="IDX952"></a>
</dt>
<dd><p>The first form solves numerically one first-order ordinary differential
equation, and the second form solves a system of m of those equations,
using the 4th order Runge-Kutta method. <var>var</var> represents the dependent
variable. <var>ODE</var> must be an expression that depends only on the independent
and dependent variables and defines the derivative of the dependent
variable with respect to the independent variable.
</p>
<p>The independent variable is specified with <code>domain</code>, which must be a
list of four elements as, for instance:
</p><pre class="example">[t, 0, 10, 0.1]
</pre><p>the first element of the list identifies the independent variable, the
second and third elements are the initial and final values for that
variable, and the last element sets the increments that should be used
within that interval.
</p>
<p>If <var>m</var> equations are going to be solved, there should be <var>m</var>
dependent variables <var>v1</var>, <var>v2</var>, ..., <var>vm</var>. The initial values
for those variables will be <var>init1</var>, <var>init2</var>, ..., <var>initm</var>.
There will still be just one independent variable defined by <code>domain</code>,
as in the previous case. <var>ODE1</var>, ..., <var>ODEm</var> are the expressions
that define the derivatives of each dependent variable in
terms of the independent variable. The only variables that may appear in
those expressions are the independent variable and any of the dependent
variables. It is important to give the derivatives <var>ODE1</var>, ...,
<var>ODEm</var> in the list in exactly the same order used for the dependent
variables; for instance, the third element in the list will be interpreted
as the derivative of the third dependent variable.
</p>
<p>The program will try to integrate the equations from the initial value
of the independent variable until its last value, using constant
increments. If at some step one of the dependent variables takes an
absolute value too large, the integration will be interrupted at that
point. The result will be a list with as many elements as the number of
iterations made. Each element in the results list is itself another list
with <var>m</var>+1 elements: the value of the independent variable, followed
by the values of the dependent variables corresponding to that point.
</p>
<p>To solve numerically the differential equation
</p>
<pre class="example">          dx/dt = t - x^2
</pre>
<p>With initial value x(t=0) = 1, in the interval of t from 0 to 8 and with
increments of 0.1 for t, use:
</p>
<pre class="example">(%i1) results: rk(t-x^2,x,1,[t,0,8,0.1])$
(%i2) plot2d ([discrete, results])$
</pre>
<p>the results will be saved in the list <code>results</code> and the plot will show the solution obtained, with <var>t</var> on the horizontal axis and <var>x</var> on the vertical axis.
</p>
<p>To solve numerically the system:
</p>
<pre class="example">        dx/dt = 4-x^2-4*y^2     dy/dt = y^2-x^2+1
</pre>
<p>for t between 0 and 4, and with values of -1.25 and 0.75 for x and y at t=0:
</p>
<pre class="example">(%i1) sol: rk([4-x^2-4*y^2,y^2-x^2+1],[x,y],[-1.25,0.75],[t,0,4,0.02])$
(%i2) plot2d ([discrete,makelist([p[1],p[3]],p,sol)], [xlabel,&quot;t&quot;],[ylabel,&quot;y&quot;])$
</pre>
<p>The plot will show the solution for variable <var>y</var> as a function of <var>t</var>.
</p>
<div class=categorybox>
&middot;
<p>@ref{Category: Differential equations} &middot;
@ref{Category: Numerical methods}
</div>
</p>
</dd></dl>

<p><a name="Item_003a-Matrices-and-Linear-Algebra"></a>
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC107" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="maxima_23.html#SEC113" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated by <em>root</em> on <em>January, 10 2014</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
 </font>
 <br>

</p>
</body>
</html>