Maxima Basics #2

Maxima Version 5.20.1
wxMaxima Version 0.8.4

(1)
With all computer algbra systems there are differences between functions and expressions.
Names are assigned to expressions using the colon. Functions are defined differently (see
below). We substitute into expressions, and we evaluate functions.

There are several ways to substitute values into expressions. You have already seen the
subst() command. Another approach is to use at().

(%i1) f: (3*x+1)*(x-1)*(x+2)^2;
Result

(%i2) at( f, x=1 );
Result

(%i3) at( f, x=-3/2 );
Result

(%i4) subst( a^2, x, f );
Result

(%i5) g: 2*x*y+y^2-x;
Result

(%i6) at( g, [x=1,y=2] );
Result

(%i7) kill( f, g );
Result

(2)
Since the example above made use of polynomials, let's look at some commands used to
deal with polynomials:
expand( expr ) expands expression expr and combines like terms.
factor( expr ) attempts to factor expression expr.
divide( expr1, expr2, var ) returns the quotient and remainder when expr1 is
   divided by expr2, where the expressions are polynomials in variable var.

(%i8) f: (2*x+1)^2*(x-3)*(5*x-2)*x^2;
Result

(%i9) expand(f);
Result

(%i10) factor(%);
Result

(%i11) divide( f, x^2+1, x );
Result

(%i12) kill(f);
Result

(3)
Maxima's solve() command is used to find exact solutions of an equation.

(%i13) f: x^2-3*x;
Result

(%i14) sol: solve(f=7,x);
Result

The solve command returned a list containing the two solutions. You can reference the
individual elements of a list using list[1], list[2], etc.

(%i15) sol[1]; sol[2];
Result

The solutions were given as equations. rhs( eq ) returns the right-hand side of eq.

(%i17) root1: rhs( sol[1] );
Result

(%i18) subst( root1, x, f );
Result

(%i19) expand(%);
Result

(%i20) kill(all);
Result

(4)
When an exact solution cannot be found, find_root() gives a numerical approximation:
find_root( eq, var, a, b ) returns the numerical approximation of a solution
of equation eq in variable var bewteen var=a and var=b.

(%i1) solve( cos(x)=x, x );
Result

(%i2) find_root( cos(x)=x, x, 0, 5 );
Result

(5)
Maxima's diff() command is used for differentiation.
diff( expr, var, n ) returns the nth derivate of expr with respect to variable var.
If n=1, the order can be omitted.

(%i3) f: 3*x^2 + 1/x + sin(x) + exp(x);
Result

(%i4) fp: diff( f, x );
Result

(%i5) diff( fp, x ); diff( f, x, 2 );
Result

(%i7) kill(all);
Result

Instead of defining f as an expression, here we'll define f as a function. To do so
we need to use " := ".

(%i1) f(x):= 3*x^2 + 1/x + sin(x) + exp(x);
Result

(%i2) f(%pi);
Result

(%i3) float(%);
Result

(%i4) diff( f(x), x );
Result

Unfortunately, if we use diff() to differentiate f(x), we get an expression, not a function.
One way to get the diff() to return a function is to use it with a dummy variable
and the at() command. Try to follow these examples...

(%i5) fp(x):= at( diff(f(u),u), u=x );
Result

(%i6) fp(x);
Result

(%i7) fpp(x):= at( diff(f(u),u,2), u=x );
Result

(%i8) fpp(x);
Result

(%i9) fp(2); fpp(%pi); f(%e);
Result


Created with wxMaxima.