<Text-field layout="Heading 1" style="Heading 1">Chapter 9: Symbolic algebra</Text-field>
<Text-field layout="Heading 2" style="Heading 2">Basics</Text-field>
<Text-field layout="Heading 3" style="Heading 3">expand</Text-field>expand( (x-1)^2*(x+2) );expand( cos(x+y) );expand( exp(x-y) );Assume:assume(x,real); expand( ln( x/(1+x^2) ) );expand( tan(x-y) );
<Text-field layout="Heading 3" style="Heading 3">combine</Text-field>restart;expand( cos(x+y) );combine(%);expand( exp(x-y) );combine(%);assume(x,real); expand( ln(x/(1+x^2)) );combine(%);restart;expand(tan(x-y));combine(%); # not goodexpand(%); simplify(%); #still not good
<Text-field layout="Heading 3" style="Heading 3">simplify, side relations</Text-field>simplify( cos(x)^2 +sin(x)^2 );simplify( (x^2-2*x+1)/(x-1) );simplify( cos(x)^2-sin(x)^2 );simplify( 2*sin(x)*cos(x), trig );combine( cos(x)^2-sin(x)^2 ); combine( 2*sin(x)*cos(x), trig );Side-relations (see ?simplify/siderels)f:= cos(x)^4- 3 +cos(x)^2;simplify( f, {cos(x)^2 = (1+cos(2*x))/2} );Compare withsubs( cos(x)^2=(1+cos(2*x))/2, f );simplify(expression,{side1,side2,side3})f:= cos(x)^4 +1 -cos(x)^2 -sin(x)^2 +3*sin(x)^6;s1:= cos(x)^2 = (1+cos(2*x))/2;s2:= sin(x)^2 = (1-cos(2*x))/2;simplify( f, {s1,s2} );
<Text-field layout="Heading 3" style="Heading 3">sort</Text-field>sort( 2 -3*x^2 -x +x^4 );sort( 1 -cos(x)^2 +cos(x) );
<Text-field layout="Heading 3" style="Heading 3">factor</Text-field>factor( x^2 -6*x +8 );
<Text-field layout="Heading 3" style="Heading 3">collect</Text-field>F:= x*ln(y) -5*x +3*ln(y) +5*exp(y);collect( F, ln(y) );And if you want to collect more than one factor at once, give collect a list of factors, like thisF:= a*x*sin(y) +b*a*x/cos(y);collect( F,[x,a] );
<Text-field layout="Heading 3" style="Heading 3">solve</Text-field>solve( x^2 -6*x +8 );solve( ln(y/x)=3, y ); solve( ln(y/x)=3, x );Exact solution:solve( 1-tan(x)^2=-2, x );Numerical solution:solve( 1-tan(x)^2=-2., x );plot( 1-tan(x)^2, x=-Pi..Pi, -3..3 );solve( 1-tan(x)^2=2, x ); # no solution
<Text-field layout="Heading 3" style="Heading 3">normal</Text-field>normal( 1/x + 1/(x+1) );expand(%);
<Text-field layout="Heading 3" style="Heading 3">numer & denom</Text-field>denom( (1+x)/(3-x^2) );numer( (1+x)/(3-x^2) );(1+x)/(3-x^2);
<Text-field layout="Heading 3" style="Heading 3">op</Text-field> op(n, expr) picks up the nth part of expr.kk:= (1+x^2)/(sin(x)+tan(x))*cosh(x)/(1+tanh(x));op(1,kk); op(2,kk); op(3,kk); op(4,kk);
<Text-field layout="Heading 3" style="Heading 3">subs</Text-field>Eq1:= cos(x)^2 -5*cos(x) +1;subs( cos(x)=y, Eq1 );Eq2:= exp(2*x)-t^2 = x*t;subs( x=xi, t=tau, Eq2 );f:= x^4 -3*x^2 +5;subs( x^2=y, f ); # not what you expected?algsubs( x^2=y, f ); # better
<Text-field layout="Heading 3" style="Heading 3">convert</Text-field>Put rational functions in partial fraction form with the parfrac optionconvert( (2*x+1)/(x*(x+1)), parfrac, x );Convert rational functions to continued fraction form with confracconvert( (2*x+1)/(x*(x+1)), confrac, x );Express functions in exponential form with expconvert( sin(x), exp, x );convert( sinh(x), exp, x );Convert expressions with sines and cosines into tangent form with tanrestart;a:= convert( (2+cos(x)^2)/(2-sin(x)^2), tan );a:= simplify(a);Convert expressions with tangents into sine-cosine form with sincosconvert( a, sincos );simplify(%);Convert English units to metric ones with convert(,metric)convert( 1.*acre, metric ); convert( 1.*MPH, metric );To see what English quantities can be converted to metric try?metricConvert expressions containing abs, Heaviside, signum, etc., into piecewise functionsF:= abs(x);F:= convert( F, piecewise, x );For instance, convert will give you a nice definition of Maple's signum function G:= signum(x);G:= convert( G, piecewise, x );Convert complex expressions to polar formconvert( x+I*y, polar );Now this is probably not exactly what you had in mind. Fortunately Maple's map command can put it in a more useful form. The command map tells Maple to apply the procedure in the first slot of map(a,b) to each of the operands of the object in the second slot, in this case the magnitude and argument expressions, The conversion procedure is evalc, so we would do thismap(evalc,%);
<Text-field layout="Heading 3" style="Heading 3">ratpoly</Text-field>The ratpoly option converts a series into a rational function. The syntax is convert(series,ratpoly,numdeg,dendeg) where numdeg is the order of the numerator polynomial and where dendeg is the order of the denominator polynomial. These two arguments are optional. Approximate the sine function.:sinap:= convert( taylor( sin(x), x=0,10 ), ratpoly );plot( [sin(x),sinap], x=0..6, color=[red,navy] );Approximate the tangent function. tanap:= convert( taylor(tan(x),x=0,10), ratpoly );plot( [tan(x),tanap], x=0..5, -10..10, color=[red,navy] );Bessel function:J0ap:= convert( taylor( BesselJ(0,x), x=0,10 ), ratpoly );plot( [BesselJ(0,x),J0ap], x=0..5, color=[red,navy] );plot( BesselJ(0,x)-J0ap, x=0..5, -.001..0.001 );
<Text-field layout="Heading 2" style="Heading 2">Algebra on matrices filled with expressions</Text-field>The dispersion relation for electromagnetic waves in the ionosphere is NiMvKiQlJm9tZWdhRyIiIywmKiQmRiU2IyUicEdGJiIiIiomJSJrR0YmJSJjR0YmRiw= .where NiMmJSZvbWVnYUc2IyUicEc= is the plasma frequency. The following shows how to find both the phase velocity NiMvJiUidkc2IyUicEcqJiUmb21lZ2FHIiIiJSJrRyEiIg== and the group velocity NiMvJiUidkc2IyUiZ0ctJSVkaWZmRzYkJSZvbWVnYUclImtH as functions of NiMlJm9tZWdhRw== :
<Text-field layout="Heading 3" style="Heading 3">1st trial:</Text-field>restart:This doesn't work because "omega[p]" makes omega a list- (array-) variable:Eq:= omega^2 = omega[p]^2 + k^2*c^2;solve( Eq, omega );Lesson: Do not ever use subscripts for anything but comments in your worksheet.
<Text-field layout="Heading 3" style="Heading 3">2nd trial:</Text-field>restart:Eq:= omega^2 = wp^2 + k^2*c^2;s:= solve( Eq, omega );Assign the 1st (positive) solution to w (not omega):w:= s;Phase velocity:vp:= w/k;To get NiMmJSJ2RzYjJSJwRw== as a function of NiMlJm9tZWdhRw==, we first solve for k : s:= solve( Eq, k );Assign the 1st (positive) solution to k :k:= s;Voila !vp;simplify(vp);assume(omega>0);vp:= simplify(vp);Group velocity :vg:= diff(w,k); # doesn't workTo see what's wrong:w;Thus, when we assign k:= s, w was automatically updated and ruined!
<Text-field layout="Heading 3" style="Heading 3">3rd trial:</Text-field>restart:Eq:= omega^2 = wp^2 + k^2*c^2;s:= solve( Eq, omega );w:= s;vp:= w/k;s:= solve( Eq, k );Assign the 1st (positive) solution to kk :kk:= s;vp;To update vp:vp:= subs( k=kk, vp );simplify(vp);assume(omega>0);vp:= simplify(vp);Group velocity :vg:= diff(w,k);vg:= subs( k=kk, vg );vg:= simplify(vg);