Maxima Book Chapter 3

Embed Size (px)

Citation preview

  • 8/13/2019 Maxima Book Chapter 3

    1/35

    Expressions, complex numbers,polynomials, and fractions in MaximaIn this Chapter we introduce Maxima functions that allow themanipulation of algebraic, logarithmic, exponential, and

    trigonometric expressions, among others. The chapter also presents manipulation of

    factorials and related functions, as well as operations with complex numbers.

    The SimplifymenuThe Simplify menu in the wxMaximaincludes all the options shown in Figure 3.1. In thisChapter we will use these menu options in the simplification of algebraic, trigonometric,factorials, and complex expressions.

    Figure 3.1. Simplify menu and submenus

    Manipulating algebraic expressionsThe following items in the Simplifymenu can be used to simplify algebraic expressions suchas polynomials and fractions!

    Simplify expression e"ui#alent to ratsimp()

    Simplify radicals e"ui#alent to radcan() Factor expression e"ui#alent to factor() Factor complex e"ui#alent to gfactor() $xpand expression e"ui#alent to expand() $xpand logarithms e"ui#alent to %,logexpan=super Contract logarithms e"ui#alent to logcontract()

    3-1 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    2/35

    To use these, and other menu items, you should ha#e the expression to be manipulatedready in the INPUTline, and then in#o&e the menu item. The following examples illustratesthe use of the Simplifymenu items listed abo#e.

    Simplify expression$nter the following expression in the INPUTline!

    and select the menu item Simplify > Simplify expressionto get the following output!

    The result of the Simplify expressionmenu item is the command ratsimp'rationalsimplification(, which, in this case, produced a factoring of the expression into two"uadratic expressions inx, each accompanied by other terms, such as y2zand y2,respecti#ely.

    In the following example, we apply the Simplify expressionmenu item to a sum offractions, to produce a single fraction!

    The two results abo#e suggest that any simplification in an algebraic expression in#ol#ingxand other #ariables will expand or collect terms around thex#ariable. In the followingtwo examplesxis the only #ariable in#ol#ed!

    Simplify radicalsSimplifies expressions in#ol#ing logarithms, exponentials, and radicals into a canonicalform. The following examples illustrates applications of the menu item Simplify > Simplifyradicals!

    3-2 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    3/35

    $xpression in#ol#ing exponentials!

    $xpression in#ol#ing logarithms!

    $xpression in#ol#ing radicals!

    Factor expressionFactors out algebraic expressions, as illustrated below. First, we factor a couple ofpolynomials!

    3-3 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    4/35

  • 8/13/2019 Maxima Book Chapter 3

    5/35

    To reco#er the simple fractional form use ratsimp

    *T$! To separate numerator and denominator of a fraction use functions n!mand denom,e.g.,

    Expand logarit"mThe Expand logarit"m menu item is a postfix operator of the form #$ logexpan%s!per& Thiscommand is used to expand a logarithm into sums or differences of logarithms, e.g.,

    'ontract logarit"mThe 'ontract logarit"m menu item performs the in#erse of the Expand logarit"m function,

    e.g.,

    3-5 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    6/35

    Factorials, combinations, and permutationsThe factorial, n(, of a positi#e integer number nis defined as the product!

    n(- n)n*+,)n*2, &&& -2+

    Thus, 2( % 2+ % 2$ -( % -2+ % ., etc. In axima, factorials are calculated by using thepostfix operator (. '/ostfix means the operator is placed after the number(. Someexamples are shown below!

    From the definition of factorial, it follows that!

    n( % n)n*+,( % n)n*+,)n*2,( % n)n*+,)n*2,)n*-,(and so on.

    CombinationsFactorials are used, for example, in combinatorial analysis for calculating the number ofcom/inations andperm!tationsof nob0ects ta&en rat a time, with n r. combination isa selection of ob0ects in which the order in which they are selected is not important. Forexample, if you ha#e a collection of ob0ects 2,,C,4,$5 and you ta&e three at a time, thenselecting, say, 2,,C5, 2,C,5, 2,,C5, etc., corresponds to the same combination ofelements since the order is not important. The tree diagram shown below illustrates all 16

    combinations of the 7 elements 2,,C,4,$5 ta&en three at a time.

    3-6 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    7/35

    The number of combinations of nelements ta&en rat a time is calculated using1!

    ')n$r, % n'r- nr= n !

    nr ! r !.

    lso,

    ')n$r, % n'r- nr=nn1n2... nr1nr !

    nr! r ! =

    nn1n2 ...nr1

    r !

    Thus, if n % 0and r % -, as in the case presented abo#e, we find that ')0$-,is e"ual to!

    lternati#ely,

    Maximaincludes function com/ination'n$r( to calculate the number of combinations of nelements ta&en rat a time. 8sing the online "elpcommand '11( we find the followinginformation about function com/ination!

    /roceeding according to the information abo#e, we first load thef!nctspac&age and thenshow some calculations of the number of combinations of 7 elements ta&en 1, 9, 3, and : ata time, respecti#ely!

    1The notation nr is also referred to as the /inomialcoefficient, since it represents the r*t" coefficient in theexpansion of the binomial )xy,n&

    3-7 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    8/35

    Since the order of selection is not important when forming a combination of ob0ects, thenthe number of combinations of nelements ta&en nat a time is +. lso, the expression for')n$n,is gi#en by

    Cn , n=nn= n !

    nn! n !=

    n !

    0 ! n !=1 ,

    which leds to the interesting conclusion that 3( % +.

    /ermutations permutation is a selection of ob0ects such that the order in which they are selected isimportant. Thus, if you ha#e 7 ob0ects, say, 2,,C,4,$5, and you randomly select three ofthem, say, 2,C,$5, then 2,C,$5, 2,$,C5, 2C,,$5, 2$,C,5, etc., are all permutations ofthose three elements. ;ou can actually produce the permutations of 2,C,$5 using thefunctionperm!tationsin Maxima!

    The number of permutations of nelements ta&en rat a time is calculated using9!

    P)n$r, % n Pr-n !

    nr!.

    lso,

    P)n$r, % n Pr- nn1n2... nr1nr !

    nr! =nn1n2... nr1

    Thus, if n % 0and r % -, as in the case presented abo#e, we find that P)0$-,is e"ual to!

    lternati#ely,

    Maximaincludes functionsperm!tation'n$r( to calculate the number of permutations of nelements ta&en rat a time. 8sing the online "elpcommand '11( we find the following

    information about functionperm!tation. *otice that Maxima pro#ides three differentonline help entries related to the wordperm!tation, so we ha#e to choose, by entering theproper number, which one of the three definitions we want to explore further. Choose 3toobtain!

    9The notation nr is also referred to as the /inomialcoefficient, since it represents the r*t" coefficient in theexpansion of the binomial )xy,n&

    3-8 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    9/35

    Since we ha#e already loaded thef!nctspac&age 'when dealing with combinations(, weproceed to show some calculations of the number of permutations of 7 elements ta&en 1, 9,3, and : at a time, respecti#ely!

    The Gamma ( ) functionThe

  • 8/13/2019 Maxima Book Chapter 3

    10/35

    The beta () functionThe beta function is defined in terms of the

  • 8/13/2019 Maxima Book Chapter 3

    11/35

    'on4ert to gammaThis menu item is used to con#ert factorial expressions into

  • 8/13/2019 Maxima Book Chapter 3

    12/35

    Simplify trigonometricThis menu item utili=es the trigonometric identity sin2)x, cos2)x, % +and the hyperbolicidentity cos"2)x, * sin"2)x, % + to simplify expressions in#ol#ing tan$ sec$ tan"$ sec", etc.,to expressions in#ol#ing only sin$ cos$ sin"$ and cos". To see examples of this command,load the demo file trgsmp&dem, i.e.,

    The way this demofile is put together, as illustrated in the example abo#e, is to show atrigonometric expression, and then apply the function trigsimpto the gi#en expression tosee the corresponding simplified expression. /ress 2$*T$>5 to see the rest of the demoexamples.

    5ed!ce trigonometricThis menu item combines products and powers of trigonometric and hyperbolic sine andcosine into sine and cosine of multiples of the angle, trying to eliminate sinand cosfromdenominators in the case of fractions.

    3-12 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    13/35

    The following example shows that function trigred!ceacts term by term!

    t this point, we can use the menu item Simplify > Simplify expression 'ratsimp( to simplifythe fractional sum to!

    ther types of reductions achie#able with trigred!ceare illustrated below!

    Expand trigonometricThis menu item allows expanding expressions such as sin)xy,, sin)26x,, etc. For example!

    ne type of expansion that re"uires redefining an option in Maximais the expansion ofhalfangle expressions. y default, Maximadoes not expand trigonometric functions of halfangles, e.g.,

    This is so because, by default, the "alfanglesoption is set tofalse!

    3-13 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    14/35

    Try setting the option "alfanglesto tr!eand repeating the expansion!

    'anonical formThis menu item is used to produce a simplification of trigonometric expressions into a"uasilinear form, i.e., a#oiding powers of trigonometric functions as much as possible.Some examples are shown below.

    second example!

    Manipulating complex numbers and expressionsThe Simplify menu offers the following submenu for the manipulation of complex numbersand expressions!

    3-14 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    15/35

    To understand the functions listed abo#e, we first pro#ide a few definitions related tocomplex numbers! complex #ariable is a #ariable of the form

    z % x iy$

    with i2% *+, wherexand yare real numbers.

    The real partof zis

    x % 5e)z,$

    while the imaginary partof zis

    y % Im)z,&

    7rap"ical representation * complex number can be represented as a point in the8rgand9sdiagram, a Cartesian coordinate system where the ordinate represents imaginary numbers.

    This representation is shown in the following figure!

    Figure 3.9. >ectangular and polar forms of a complex number.

    The figure shows two different representations of the complex #ariable z, its Cartesian orrectang!lar form'xiy( and itspolar form'rei(. The radial distance

    r % ?z? - x2y2

    is referred to as the mod!l!sof the complex number, while

    % 8rg'z( - tan1yx

    is referred to as the arg!mentof the complex number. The real and imaginary parts, xandy$ of the rectangular form of the complex number can be calculated in terms of themodulus and argument, r and , by using!

    x % r cos),, y % r sin),&

    3-15 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    16/35

    The polar form representation uses the 4e oi#re formula for complex numbers, namely,

    e i=cos i sin .

    s a curious note, if one replaces = into this expression, the result is a combination ofsome of the most famous numbers in mathematics!

    ei=1

    This expression in#ol#es the numbers!

    e the base of the natural logarithms i the unit imaginary number the ratio of the length of the circumference to its diameter 1 the unit negati#e number

    8sing the $uler formula, the e"ui#alence of the rectangular and the polar representationsof a complex number becomes ob#ious!

    z=r e i=rcosisin =r cos i r sin=xi y .

    *ext, we present some of the complex #ariable operations a#ailable in Maximausing theitems in the Symplify >'omplex simplification submenu.

    'on4ert to rectformThis menu item con#erts a complex expression into its rectangular form. This command

    can be used to show the results of complex number operations, as illustrated in theseexamples. First we define two complex numbers =1 and =9 and attempt an addition!

    8sing the 'on4ert to rectform'rectform( command we get!

    The following examples show the command rectformapplied to subtraction, multiplication,di#ision, and powers of complex numbers!

    3-16 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    17/35

    8sing actual numbers!

    'on4ert to polarformThis menu item con#erts a complex expression into its rectangular form. This commandcan be used to show the results of complex number operations, as illustrated in theseexamples. First we define two complex numbers z+and z2as follows!

    In this case we use subindices to define the #ariables t"eta:+;and t"eta:2;. The sum ofthe two complex numbers is a long expression in its polar form!

    3-17 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    18/35

    ultiplications, di#isions, and powers will show more manageable expressions, although theuser needs to reply to additional re"uests for information from Maxima!

    The following examples use actual numbers!

    3-18 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    19/35

    7et real partThis menu item extracts the real part of a complex #ariable or expression!

    7et imaginary partThis menu item extracts the imaginary part of a complex #ariable or expression

  • 8/13/2019 Maxima Book Chapter 3

    20/35

    ExponentializeThis menu item is the in#erse of the

  • 8/13/2019 Maxima Book Chapter 3

    21/35

    The following examples co#er applications of the functions ca/s, carg, and con=!gate forcomplex expressions!

    Baurent series expansion for a complex expression re"uires a point of expansion z3& TheBaurent series resembles a Taylor series expansion but it includes both positi#e andnegati#e powers. The resid!eof a complex expression is the coefficient of the power '1(term in the expansion of the expression in a Baurent series.

    For additional information on Baurent series chec& out the following online lin&s!

    Ai&ipedia lin&! http!en.wi&ipedia.orgwi&iBaurentDseries Aolfram athworld lin&! http!mathworld.wolfram.comBaurentSeries.html

    Function resid!ere"uires the complex expression being expanded, the complex #ariable,and the point of expansion, and returns the residue in the complex plane for theexpression. $xamples!

    3-21 Gilberto E. Urroz, 2008

    http://en.wikipedia.org/wiki/Laurent_serieshttp://mathworld.wolfram.com/LaurentSeries.htmlhttp://mathworld.wolfram.com/LaurentSeries.htmlhttp://en.wikipedia.org/wiki/Laurent_series
  • 8/13/2019 Maxima Book Chapter 3

    22/35

    Substitution and other menu items for expression manipulationThe last set of functions in the Simplify menu include the following items!

    S!/stit!te&&&This menu item acti#ates a dialogue form that allows the substitution of a #ariable into anexpression. For example, the following two examples show the dialogue form and theresulting entry into the wxMaxima window!

    Chec&ing the 2 5 5ationalbox in the the dialogue form implements function rats!/st'rational s!/stitution( rather than s!/stalone. The difference, in this example, is that arational simplification is applied to the resulting expression.

    )ere is another example!

    3-22 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    23/35

    n alternati#e way to use function s!/st is to create a list of substitutions using e"ual signs,as illustrated in these examples!

    E4al!ate no!n formsNo!n forms, as opposite to 4er/ forms, are executable expressions in Maximathat remainune#aluated. The item menu E4al!ate no!n formsallows the e#aluation of those

    une#aluated expressions. To produce an une#aluated expression typically you precede itwith an apostrophe. Some examples of une#aluated expressions, and their result after theE4al!ate no!n formsmenu item is acti#ated, are shown below!

    Toggle alge/raic flagThe Maxima Man!al 'select it using ?elp > Maxima "elp( has a simple entry for thealge/raicflag. The Man!alindicates that the default #alue of the alge/raicflag isfalse$and that it must be set to true 'using, alge/raic tr!e( Ein order for the simplification ofalgebraic integers to ta&e effect. y using this menu item you can toggle the alge/raicflag between tr!eandfalse. To find out about the current setting use 'default set(!

    3-23 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    24/35

    8dd alge/raic e@!ality&&&This menu item acti#ates the tellratfunction to produce algebraic e"uality betweenexpressions. >efer to the Maxima Man!alfor the operation of this function. cti#ate theMaxima Man!alusing ?elp > Maxima "elp, clic& on the Index tab, and type tellrat!

    Mod!l!s comp!tation&&&The menu item Mod!l!s comp!tation&&&allows the user to set the modulus for modulararithmetic calculations. The default #alue isfalse. The user can set the mod!l!s #alue toan integer #alue, say, 9, 3, etc. Typically the modulus is a positi#e prime number. Thefollowing references address the issue of modulus arithmetic!

    Ai&ipedia lin&! http!en.wi&ipedia.orgwi&iodularDarithmetic

    Aolfram athworld lin&! http!mathworld.wolfram.comodularrithmetic.html

    Some examples of modular arithmetic calculations are shown below. First, examples withmod!l!s % -

    3-24 Gilberto E. Urroz, 2008

    http://en.wikipedia.org/wiki/Laurent_serieshttp://mathworld.wolfram.com/ModularArithmetic.htmlhttp://en.wikipedia.org/wiki/Laurent_serieshttp://mathworld.wolfram.com/ModularArithmetic.html
  • 8/13/2019 Maxima Book Chapter 3

    25/35

    The second set of examples correspond to mod!l!s % 0!

    Simple operations with polynomialsIn this section we pro#ide examples of functions that apply to polynomials.

    coeffThe coefffunction, coeff(p,x,n), is used to extract the coefficient of the #ariablex oforder nin the polynomialp!

    di4ide'also 'alc!l!s >

  • 8/13/2019 Maxima Book Chapter 3

    26/35

    @!otient$ and remainderThe @!otientand remainderfunctions, quotient(p,q) and remainder(p,q), produce,respecti#ely, the "uotient and residual of the polynomial di#isionpA@!

    ratdiffThe ratdiff'rational differentiation( function, ratdiff(p,x), produces the deri#ati#e of arational functionpwith respect to #ariablex!

    allroots'E@!ations > 5oots of polynomial(The allrootsfunction, allroots(p)or allroots(p,x), calculates all the rootsxof apolynomialp!

    realroots'E@!ations > 5oots of polynomial )real,(The allrootsfunction, realroots(p)or realroots(p,x), calculates the real rootsxof apolynomialp!

    3-26 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    27/35

    gcd ''alc!l!s > 7reatest common di4isor&&& (Thegcdfunction calculates thegreatest common di#isor for two or more polynomials, e.g.,

    Bet@s add one more polynomial to thegcdfunction!

    Functiongcd can also be applied to integers!

    "ornerFunction "ornerproduces the expression corresponding to the )orner@s rule for e#aluatingpolynomials. The following example shows the )orner@s rule for a list of two polynomials!

    lcm''alc!l!s >Beast common m!ltiple &&&(The lcmfunction calculates the least common multiple for two polynomials, or integers.This function belongs to thef!nctspac&age, which must be loaded before applying thefunction. Function lcmcan be in#o&ed from the 'alc!l!s menu, howe#er, before using thismenu item it is necessary to load thef!nctspac&age. Thus, the first command to enter is!

    3-27 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    28/35

    The following example shows function lcmapplied to pairs of numbers!

    *ext, we apply function lcmto a pair of polynomials!

    *T$ 1! Function lcmbelongs to pac&agef!nctswhich contains a number of other usefulfunctions that apply to polynomials and numbers. The contents of pac&agef!nctsarepresented in a section at the end of this Chapter.

    *T$ 9! For additional information on polynomials acti#ate the Maxima Man!al'?elp >Maxima "elp( and find the Polynomial chapter in the 'ontentstab.

    3-28 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    29/35

    Simple operations with fractionsIn this section we pro#ide examples of functions that apply to fractions.

    com/ineThe com/inefunction can be used to collect fractions with the same denominator!

    partfrac''alc!l!s > Partial fractions&&&(

    Thepartfrac function decomposes a single fraction into its partial fractions!

    cfdisrep ''alc!l!s > 'ontin!ed fraction(The cfdisrepfunction is used to produce a continued fraction gi#en the coefficients ofthose fractions as illustrated in this example!

    3-29 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    30/35

    Functions in the functspacageThis section presents examples of functions in thef!ncts pac&age. The descriptions of thefunctions was ta&en from the Maximaonline help facility forf!ncts, i.e.,

    Interestingly enough, function lcm, which was presented in an earlier section, is notincluded in the help entries forf!ncts.

    rempart 'expr, n(>emo#es part nfrom the expression expr. If nis a list of the form 2l$m5 then parts lthroughmare remo#ed.

    wrons&ian '2f+$ &&&$ fn5,x(>eturns the Arons&ian matrix of the functionsf+$ &&&$ fnin the #ariablex. f+$ &&&$ fnmay bethe names of userdefined functions, or expressions in the #ariablex.

    3-30 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    31/35

    tracematrix'M(>eturns the trace 'sum of the diagonal elements( of matrix M.

    rational'z(ultiplies numerator and denominator of zby the complex con0ugate of denominator, thusrationali=ing the denominator.

    similar result is obtained by using function rectform!

    gcdi#ide'p$@(Ahen taCegcd is tr!e,gcdi4ide di#ides the polynomialspand @by their greatest commondi#isor and returns the ratio of the results.

    3-31 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    32/35

    Ahen taCegcd isfalse,gcdi4ide returnspA@.

    arithmetic 'a$d$n(>eturns the nth term of the arithmetic series a$ ad$ a2d$ &&&$ a)n*+,d&

    geometric 'a$r$n(>eturns the nth term of the geometric series a$ ar$ ar2$ &&&$ arn*+.

    harmonic 'a$/$c$n(>eturns the nth term of the harmonic series aA/$ aA)/c,$ aA)/2c,$ &&&$ aA)/)n*+,c(.

    arithsum 'a$d$n(>eturns the sum of the arithmetic series from +to n.

    geosum 'a$r$n(>eturns the sum of the geometric series from +to n. If nis infinity 'inf( then a sum is finiteonly if the absolute #alue of ris less than 1.

    gaussprob 'x(>eturns the

  • 8/13/2019 Maxima Book Chapter 3

    33/35

    )ere is a list of ordinates of the standard normalpdf!

    )ere is a list of probabilities of the inter#als *+ D x D +$ *2 D x D 2$ and *- D x D -$respecti#ely,

    *otice that integrals of thega!sspro/'x( function are gi#en in terms of the error f!nction'erf(. To find out about the error function chec& the Maximaonline help!

    Finally, a plot of the standard normalpdfis shown below!

    3-33 Gilberto E. Urroz, 2008

  • 8/13/2019 Maxima Book Chapter 3

    34/35

    gd 'x(

    >eturns the eturns the in#erse

  • 8/13/2019 Maxima Book Chapter 3

    35/35

    co#ers 'x(>eturns the co#ersed sine G1 sin 'x(@.

    exsec 'x(>eturns the exsecant Gsec 'x( 1@.

    ha# 'x(>eturns the ha#ersine G'1 cos'x((9@.