maxima book chapter 1

Upload: prakushprakush

Post on 04-Jun-2018

221 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/13/2019 Maxima Book Chapter 1

    1/36

    Introduction to MaximaMaxima is a symbolic-based mathematical software providing a numberof functions for algebraic manipulation, calculus operations, matrix andlinear algebra, and other mathematical calculations.

    Maxima web pageThe Maxima web page is located at:

    http://maxima.sourceforge.net/

    Read the description of Maxima shown in this page. The page also includes a number oflin s including a Download lin . !ownload and install Maxima in your computer asindicated in the download page.

    The Maxima web page also includes a Documentation lin with a number of tutorials on theuse of Maxima .

    xMaxima and wxMaxima The figure below shows the listing of programs and documents available for Maxima 5.14.0in a Windows Vista installation.

    "ou will notice that there are two possible instances of Maxima called XMaxima andwxMaxima . #hile both allow the user access to the $axima commands, the difference is

    in the graphic user interface %&'I( used to communicate with Maxima . XMaxima)n example of the XMaxima interface is shown in *igure +.+. The top of the &'I is theinput window for Maxima commands. The lower part is a display of a Maxima rimerdocument providing the user with some information about getting started with Maxima . Inbetween the top and lower part of the display you will find buttons labeled File , Back ,

    1-1 Gilberto E. Urroz, 2008

    http://maxima.sourceforge.net/http://maxima.sourceforge.net/
  • 8/13/2019 Maxima Book Chapter 1

    2/36

    Forward , Edit , O tions , and !rl : The last button refers to the file specification shown inthe field immediately to its right. In this case, the file specification reads:

    "ile#$%#$&'O(')*$M)X+M)*1.0$s,are$maxima$514*1.0$xmaxima$+- 'O*1./ M

    The full reference to this file should be:

    "ile#$%#$&ro ram Files$Maxima 5.14.0$s,are$maxima$5.14.0$xmaxima$intro.,tml

    The X $ axima &'I abbreviates some of the sub-folders in the first file specificationproducing the reference shown above, which could be a bit confusing. The full filespecification shows the location of the file being shown in the bottom window of the

    X $ axima &'I. This ,tml file is located in the Maxima installation as indicated above.

    *igure +.+. XMaxima starting &'I

    1-2 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    3/36

  • 8/13/2019 Maxima Book Chapter 1

    4/36

    in the Maxima &rimer , we activated the input without copying it to the top window. Theresult, however, is available in the top window as output + 23o1 . )lso, notice that

    XMaxima presents the result of the integral as closely as possible as a two-dimensionalmathematical expression, i.e.,

    2 x - 1 2 atan(-------) log(x - x + 1) sqrt(3) log(x + 1)

    (%o1) - --------------- + ------------- + ---------- 6 sqrt(3) 3

    as opposite to a one-dimensional mathematical entry, i.e.,

    -log(x^2-x+1)/6+ atan((2*x-1)/sqrt(3))/sqrt(3) + log(x+1)/3 .

    The full mathematical operation calculated in this example can be, on paper, written as

    dx1 x3 =

    ln x2 x 16

    tan 1 2 x 1 3 3

    log x 13

    .

    The user is invited to continue reading the Maxima &rimer document and double-clic onthe different examples listed to learn the basic operation of Maxima . *ollowing thoseexercises, one may notice, for example, that in the XMaxima interface, the mathematicalconstant %the ratio of the length of a circumference to its diameter( is referred to as%pi . )lso, infinity % ( is referred to as in" .

    The Maxima &rimer examples include also plots that are produced in their own separategraphics window, e.g., the commands

    plot2d(sin(x),[x,0,2*%pi]) plot3d(x^2-y^2,[x,-2,2],[y,-2,2],[grid,12,12])

    produce, respectively, the two-dimensional and a three-dimensional graphs shown below.

    1-4 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    5/36

    1lic -off the graphical windows before continuing with the other commands in the Maxima&rimer .

    wxMaximawxMaxima uses an interface as shown in *igure +.0, below.

    *igure +.0. The wxMaxima &'I.

    This interface is more sophisticated than that of XMaxima for the following reasons:

    wxMaxima produces true two-dimensional mathematical output wxMaxima provides most Maxima commands in menus %e.g., E6uations7 )l e8ra7

    etc. ( ome commands can be activated by using the buttons shown at the bottom of the

    interface, e.g., 9im li":7 Factor7 etc.

    wxMaxima provides dialogues to enter parameters of selected commands. wxMaxima maintains a command line history buffer where previously used commandscan be accessed, repeated, or edited.

    wxMaxima allows mixing text with mathematical expressions to produce printabledocuments.

    The current version of wxMaxima supports simple animations %to see the currentversion use the menu item /el ; )8out (.

    1-5 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    6/36

    ) web page for wxMaxima is available here:

    http://wxmaxima.sourceforge.net/wi i/index.php/$ain2 age

    *or hints on the efficient use of wxMaxima visit:

    http://wxmaxima.sourceforge.net/wi i/index.php/3owtoT4: 5ecause of the additional features available in wxMaxima , we will use this &'I

    exclusively to present the examples contained in this and subse6uent chapters. #e will notbe using XMaxima anymore in this or subse6uent chapters.

    wxMaxima menusTa e some time to explore the different menus in the wxMaxima &'I:

    The File menu contains items typically found in windows-based applications such asO en7 'ead "ile7 9ad , and press 7. The dialogue will access thesection of the Maxima Manual corresponding to the re6uested command.

    Exam le : enters a series of examples of applications of the re6uested commandinto the wxMaxima interface. Try, for example, inte rate , and press 7.

    ) ro os : use this dialogue to enter a eyword to search for a command that issimilar to the eyword. *or example, if you were see ing information onintegration, you could enter the word inte ra , to get a listing of commands thatmay be related to inte ra . Then, you can use Descri8e or Exam le with one ofthe commands listed.

    9,ow ti : shows tips on the use of Maxima .

    Build in"o : provides information on the current version of Maxima . Bu re ort : provides a web site where users can report errors in the operation ofMaxima , or unexpected results of some operations. These 8bugs9 are reportedto the programming team and solutions to them %if available( get incorporated inthe new versions of the software.

    )8out : provides the current version of wxMaxima . otice that the versions ofMaxima and

  • 8/13/2019 Maxima Book Chapter 1

    7/36

    moment of typing this boo , showed Maxima version .+;.< and wxMaximaversion ( rint document%;( 1onfigure wx$axima% ( 1opy selection

    %?( !elete selection%=( Insert text%@( Insert input group%A( Interrupt current computation%+

  • 8/13/2019 Maxima Book Chapter 1

    8/36

  • 8/13/2019 Maxima Book Chapter 1

    9/36

    The percentage %G( operator.The percentage %G( symbol represents the most recent result.Try these examples:

    xp(-2 !)*sin(3*%pi/11)" loat(%)" xp(-3)" loat(%)"log(!)" loat(%)"

    To access the second-to-last commans use %2, the third-to-last, use %3, and so on.

    $athematical constants. ome of the common mathematical constants available in Maximaare:

    % base of the common logarithms % & xp(1) (%i imaginary unit % &sqrt(-1) (in real positive infinityin real negative infinityin init complex infinity% p i the golden ratio % (% pi ratio of length of circumference to its diameter % (%ga a 4ulerHs constant % (als , tr. boolean values %or logical values(

    3ere are some examples to try %in some examples we use function is to chec whethercomparisons of numbers are true or false(:

    loat(%p i)" loat(%pi)" loat(% )"%ga a"is(3 2)"is(3 2)"is(x 3)"int grat ( xp(-x^2/2),x,-in ,in )"int grat ( xp(-x^2/2),x, in ,in )"

    ome examples of complex numbers. The unit imaginary number i is entered as %i inMaxima . 3ere are some examples of complex number calculations:

    41#3+!*%i" 42#-2+6*%i"41+42"41-42" xpand(41*42)" xpand(41^2)"

    The following functions apply to complex numbers:

    ca8s %complex a8s olute value( calculates the moduluscar %complex ar ument( calculates the argumentrect"orm generate rectangular %1artesian( form

    olar"orm generate polar formreal art extract the real part

    ima art extract the imaginary partcon?u ate calculates the complex con ugate

    The following examples illustrate some of these functions:

    a$s(41)"arg(41)"42"-42" on5.gat (42)" xpand(42* on5.gat (42))"r t or (41/42)"r t or (sqrt(41))"polar or (41)"polar or (42)"

    1-9 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    10/36

    Using the button panelThe bottom of the xwMaxima &'I contains +0 buttons that can be used for commonoperations. The collection of buttons is shown in the figure below, with the Maximacommands associated with them.

    5uttons %+( through %;(, and %=( through %+( *actor: factors an algebraic expression, e.g., x^2+y^2-2*x*y" [si pli y(r)]

    %;( 4xpand: expands an algebraic expression, e.g., (x+1)*(x-1)*(x^2+1)" [7xpand]

    % ( olve...: solves an e6uation, e.g.,

    %?( lot 0!...: produces an x : %two dimensional( plot, e.g.,

    1-10 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    11/36

    %=( implify%tr(: trigonometric simplification in terms of sin and cos ,e.g., tan(x)[ i pli y (tr)]

    %@( 4xpand%tr(: expands a trigonometric expression, e.g., sin(x+y) [7xpand(tr)]

    %A( Reduce%tr(: convert powers of trigonometric functions to those of multiples of theangle, e.g., x+3* os(x)^2-sin(x)^2 D[8 d. (tr)]

    %+

  • 8/13/2019 Maxima Book Chapter 1

    12/36

    %+0( lot>!: produces a three-dimensional plot, e.g.,

    Using the full button panelThe button panel described above is referred to as the Basic button panel. It is possible toactivate a Full button panel by using the menu option Edit ; %on"i ure. This activates awxMaxima con"i uration window as shown next:

    1-12 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    13/36

    elect the option Full in the Button anel drop-down menu to activate the Full buttonpanel, and press J 7 K. wxMaxima will respond with the following message:

    ress J 7 K in this message form, and then J 7 K again in the wxMaxima con"i uration

    window, and clic off wxMaxima . The Full button panel will not be active until you re-startwxMaxima .

    #hen you re-start wxMaxima , the bottom part of the interface will show the Full buttonpanel:

    which now includes 0< buttons, instead of the +0 buttons of the Basic button panel. Thenew buttons are shown in the following figure, labeled %+>( to %0( through %0

  • 8/13/2019 Maxima Book Chapter 1

    14/36

    %+>(sum : allows setting up and calculating a summation, e.g.,

    %+;( roduct : allows setting up and calculating a product, e.g.,

    %+ (di"" : calculates a derivative, e.g.,

    1-14 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    15/36

    %+?(inte rate : calculates an integral

    %+=(limit : calculates a limit

    1-15 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    16/36

    %+@(ta:lor : calculates a Taylor series for an expression:

    %+A(su8st : substitute an expression into a variable name

    %0

  • 8/13/2019 Maxima Book Chapter 1

    17/36

    Using Greek lettersIn order to write &ree letters in Maxima you need to have the font 9&+onic installed in yourcomputer. "ou can download this font from:

    http://www.drshirley.org/fonts/ Ionic.ttf

    )fter installing the font in your computer, you need to select it to show &ree characters inyour wxMaxima interface. roceed as follows:

    elect the menu option Edit;%on"i ure 1lic on the 9t:le tab 1hec -off the !se reek "ont entry, and select 9&+onic ress 7

    To enter &ree letters type the 4nglish name of the letter in an expression, or precede thename with the percentage symbol %G(, e.g.,

    a tor($ ta^2-1)"r t or (1/(%alp a+%$ ta*%i)"xpand((alpa-1)*($ ta+ga a))"xpand((%alp a-1)*(%$ ta+%ga a))"

    otice the difference between typing amma and 3 amma in the last two examples. Typing amma %without G( produces the upper-case &ree letter which represents the &ammafunction from mathematics, whereas, Ggamma produces 4uler constant , defined, as thelimit as n , of the 6uantity

    k = 1

    n1

    k ln n .

    To illustrate the use of the &amma function try the followingexercises in wxMaxima :

    ga a(2 !)"plot2d(ga a(x),[x,0 !,3 0]) D

    Examples from the Equations menuIn this section we present some examples of applications fromthe E6uations menu. #e use it to illustrate the use of menussuch as E6uations7 )l e8ra7 1alculus, etc. ) listing of the

    available applications in the E6uations menu is shown below:Try the following examples by selecting entries from thismenu:

    9ol

  • 8/13/2019 Maxima Book Chapter 1

    18/36

    9ol

  • 8/13/2019 Maxima Book Chapter 1

    19/36

    9ol

  • 8/13/2019 Maxima Book Chapter 1

    20/36

    +nitial

  • 8/13/2019 Maxima Book Chapter 1

    21/36

    9ol

  • 8/13/2019 Maxima Book Chapter 1

    22/36

    Restarting Maxima ince the inputs and outputs in your wxMaxima interface will be different than thisexample, letHs restart Maxima by using the menu option Edit ; 'estart Maxima7 and pressJ 7K at the prompt. This action will clear Maxima@ s memory and reset the interface to thatshown in *igure +.0 %see above(. )t this point, only input (%1) will be available. MetHs trythe following session. Type the commands as shown next:

    perations on input and output referencesow, we are going to use the input and output references to perform operations. Try thefollowing commands:

    Thus, references such as Gi+, Go+, etc., act li e variable names that can be operated uponas any other variable. )n alternative would be to actually assign variable names to theexpressions entered. To try this approach we will also illustrate the use of the commandhistory for performing operations.

    1-22 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    23/36

    'sing the command history in wxMaxima 4very single command that you enter in wxMaxima gets stored into a command ,istor:buffer. This buffer is accessible by clic ing on the +-&! line and using the up and downarrow eys in your eyboard. )s you press the upper arrow ey once, the last command willbe shown. )s you eep pressing that ey, the second-to-last command, third-to-lastcommand, etc., will be shown in the +-&! line. *or example, for the present exercise,

    clic in the +-&! line, and press the upper-arrow ey until you recover the very firstexpression entered, namely:

    Then, use the left-arrow ey to move the cursor to the left of the first parentheses, andtype:

    a#

    then press J4 T4RK, or clic on the Enter command button: . The result is thefollowing:

    ow, we can refer to variable a for performing operations on this expression, e.g.,

    The command history can be accessed, therefore, through the use of the up- and down-arrow eys in your eyboard. nce a command is accessed this way, you can either pressJ4 T4RK to repeat it, or edit it in the I 'T line in order to perform a different operation.

    4nd-of-line charactersIt was mentioned earlier that every Maxima command ends in a semi-colon %D(, and that ifone fails to enter that end-of-line character, wxMaxima will enter it automatically. Thefact is that, besides the semi-colon, there is also a su ress out ut character, namely, the

    dollar sign %N(, which can be used as end-of-line character. 'sing the dollar sign %N( to enda Maxima statement suppresses the output of the command. 3owever, the command getsexecuted in memory. *or example, try the following commands:

    1-23 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    24/36

    In input %Gi++(, above, variables r and s are assigned the values 5 and > 7 respectively, butno output is shown because the statements end in a dollar sign %N(, rather than in a semi-colon %D(. 3owever, output %Go+>( shows that the statement rB0OsB0D was evaluatedproperly.

    The use of the dollar sign %N( as end-of-line character saves space in the wxMaxima

    interface as illustrated in the following example:

    otice that the dollar sign %N( in input %Gi+;( suppresses the output for the differentiale6uation m:ODE1 . )lso, notice the use of the &ree character ome a %( as a coefficientin the differential e6uation m:ODE1 . *urthermore, notice that, in attempting a solutionfor m:ODE1 , Maxima doesnHt now a-priori what the value of is. o, Maxima as s fromthe user whether is Pero or nonPero. In this example, the user types nonAero , andMaxima returns the solution.

    aving your sessionTo save your session use the menu option File ; 9a

  • 8/13/2019 Maxima Book Chapter 1

    25/36

    Reloading your sessionRestart Maxima %Edit ; 'estart Maxima ( and use the menu item File ; O en to browse yourcomputer file system. *or example, in a Windows Vista environment, I located the file Iwant to load in the following dialog form:

    In this case, Maxima opens the file and executes every command, stopping at input %Gi+ (where it as s again about the value of coefficient w in variable m:ODE1 . Repeating theresponse nonAero allows Maxima to continue evaluating the file to recover the entiresession saved.

    rinting your sessionTo produce a hard-copy of your session use the menu item File ; &rint.

    Moading a session without executing it)n alternative way to load a saved session is by using the menu item File ; 'ead File . 'singthis option will list all the commands in the session without executing it. The commandswill be available in the command history, and could be reactivated by using the up- anddown-arrow eys, and pressing J4 T4RK when the proper command is in the +-&! line.

    Interrupting a calculationIf, for some reason, wxMaxima seems to be hung up in a calculation, you can interrupt theprocessing by using the menu item Maxima ; +nterru t , or type %ntl ( . )lternatively, usethe interrupt button in the menu bar:

    1-25 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    26/36

    4nding your sessionTo end your session use the menu item File ; Exit , or clic the JxK in the upper right cornerof the wxMaxima window. This action produces the dialog form shown below.

    elect J 7K if you donHt want to save your current session. therwise, press J1ancelK, saveyour session as indicated above, and exit wxMaxima once more.

    Formatting your sessionThis section includes some examples of the use of text for commenting your session, as wellas inserting sections and titles in your session.

    Inserting text %comments( in wxMaxima To enter text in wxMaxima use the menu item Edit ; +nsert ; ext. The characters /C willbe shown above the next input reference. Type one or more lines of text at the currentcursor location. This line %or lines( of text can be used to comment your session. )nexample is shown next:

    Text lines contained in saved session files get loaded with the rest of the commands whenusing File ; O en or File ; 'ead "ile .

    Inserting a title or a section in wxMaxima To insert a title use the menu item Edit ; +nsert ; itle . This operation is similar toinserting text, except that the text is provided in a larger font.

    To insert a section use the menu item Edit ; +nsert ; 9ection . This operation is also similarto inserting text, except that the text is provided in a larger font and with an underline.

    The following example shows a title and a section insertion in a wxMaxima session.

    1-26 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    27/36

    Inserting inputThe menu item Edit ; +nsert ; +n ut produces a prompt input as illustrated in the followingexample:

    If you enter a new command in the I 'T line, then the statement in front of the inputprompt remains unevaluated. 3owever, if you clic on the input prompt statement, thusselecting it, and do a right-clic , you can evaluate the command by selecting the option'e e

  • 8/13/2019 Maxima Book Chapter 1

    28/36

    Additional session management in wxMaximaIn this session we explore some of the menu items under the Maxima menu, namely:

    %lear memor: : clears all variables user-defined functions - e6uivalent to ill(all)" )dd to at, : allows user to select folders to add to the search path for Maxima 9,ow "unctions : lists all user-defined functions in the current session % .n tions" (

    9,ow de"inition : provides a dialogue form to re6uest function definitions in session 9,ow

  • 8/13/2019 Maxima Book Chapter 1

    29/36

    The option Delete "unctions produce the dialogue:

    To delete functions "1 and " we enter those names in the dialogue. The result is shownbelow:

    The option Delete

  • 8/13/2019 Maxima Book Chapter 1

    30/36

    Creating a batch fileIn an earlier exercise we saved a file called m:FirstMaxima9ession.wxm . In this section wewill show you how to create a Maxima batch file out of your saved session.

    In order to create a batch file we need to edit the session file using a text editor. In this

    example I will use the -ote ad text editor to open the session file. -ote ad isavailable at

    http://notepad-plus.sourceforge.net/u /site.htm .

    #hen opened with -ote ad , the file m:FirstMaxima9ession.wxm loo s as follows:

    otice that you are warned in the very first line of the file to not edit the file by hand.This is for the wmx file. If you change anything in the file it may not be readable bywxMaxima again. The way to proceed is to save the file as a batch file, with the .macsuffix. ave it, for example, as m:FirstMaximaBatc,File.mac7 and edit it to loo as shownbelow. This is the batch file that includes a number of comment lines %text between /Cand C/(, and Maxima commands.

    1-30 Gilberto E. Urroz, 2008

    http://notepad-plus.sourceforge.net/uk/site.htmhttp://notepad-plus.sourceforge.net/uk/site.htm
  • 8/13/2019 Maxima Book Chapter 1

    31/36

    To load a batch file use the menu item File ; Batc, "ile , and select the proper file to load.The result of the batch file operation will be shown in your wxMaxima window. otice,however, that the comment lines are not shown in the wxMaxima window. If you want toshow explanatory text from your batch file, you may want to replace the comments by astring, ma ing sure that the string ends in a dollar sign %N( rather than in a semi-colon %D(.

    1-31 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    32/36

    #ith theses changes, the output in the wxMaxima is now well documented, although thecomment strings are now part of the input %with no output(, rather than inserted text.art of the output from the batch file is shown below:

    ) batch file can also be created from scratch. imply type the Maxima commands in a textfile and save it with the suffix .mac . 3ere is an example of a batch file created fromscratch:

    1-32 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    33/36

    Important basic functionsThis section addresses a few basic functions and operators of general application inmathematical functions and that were not addressed in any of the previous sections.

    4valuation or not evaluation of an operationIn many of the examples presented above related to differential e6uations we use an

    apostrophe %H( in front of the derivative operator, di""7 in order to avoid its evaluation. Toillustrate the difference between the entry Hdiff and diff, see the following example:

    In the first expression, using Hdiff%x,t,0( produces as output the derivative thus indicated.3owever, in the second expression, Maxima evaluates the re6uired derivatives. incefunction x2t has not been defined, the derivatives in the second expression evaluate toPero, and the result is x C e t .

    The following example shows an non-evaluated integral:

    )n example of a summation is shown next:

    )pplications of e< *unction e< evaluates an expression in a given environment determined by a number ofarguments. *or complete information on function e< , use the menu item /el ; Descri8e ,and enter the name e< in the dialogue form. In this document we will present only somespecific examples of the use of function e< .

    1-33 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    34/36

    ubstituting constants in an e6uation before solving it:

    *orce floating-point evaluation of rational numbers:

    *orce derivative calculation after result has been suppressed:

    !erivative and integral calculations can be forced with the option nouns :

    These examples illustrates how to list an expression and their evaluation in the sameline. It also introduces the idea of nouns in Maxima evaluation.

    1-34 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 1

    35/36

    ouns and verbsTo understand the use of the argument nouns in the examples above, please open theMaxima Manual , available through the menu item /el ; Maxima ,el , and find section.> -ouns and

  • 8/13/2019 Maxima Book Chapter 1

    36/36

    The following is another example related to the function inte rate.