Basic syntax; Almost any mathematical expression is available in Maple. The operations addition , subtraction(), multiplication ( * ), and division must be explicitly stated. Powers are denoted with a ^. Thus 3^2 is Maple for Square roots can be taken with the sqrt(expr) command and of course with the power command. We have sqrt(8) and 8^(1/2) mean the same thing, namely
The semicolon, ( ; ) Every Maple command must end with a semicolon. It is the semicolon that signals to Maple that the command is ready to be executed. Thus we have the quadratic equation.
> x^2-3*x+3;
Two mathematical statements can be placed on the same line. Usually there will be a line of output for each command. For example,
> x^2-3*x+3;subs(x=2,x^2-3*x+3);
1
Exactness paradigm. Maple reports answer only if they are exact with the exception that if decimal numbers are implied, then Maple will make approximate computations. For example,
> arctan(1);
> arctan(1.0);
0.7853981634
In the first expression the one is the exact one. Therefore, Maple returns an exact answer. In the second expression, the request to find the inverse tangent of 1.0 signals that the one is not exact, that the number 1.0 is itself an approximation (to something). Hence, it returns an approximation to the answer. Similarly, we have
> sqrt(8); sqrt(8.0);
2 sqrt(2)
2.828427125
"Though not a mathematical command, help is a command we strongly recommend that every
Maple user become familiar with. The Maple help pages are
comprehensive and
very well written."
Help. Help is a command with syntax:
?topic or ?topic,subtopicor
help(topic) or help(topic,subtopic)
There are other forms, as well. In addition, one can obtain help by selecting the Help+Full Topic Search buttons from the main menu line. Examples:
> ?help;
> help(intro)
gives an excellent introduction to Maple.
> ?least squares;
gives important information on how to compute the least squares approximation of a data set.
Assignment. If you wish to assign a mathematical expression to a new variable use the := notation. For example, the command
> f := sqrt(8);
will assign the value to the variable f. It is very easy to forget the colon in the assignment process. This is one mistake you are likely to make - even more than once.
Expand. The expand command is useful for expanding various mathematical expressions. The syntax is:
expand(expr, expr1, expr2, ..., exprn);
where the arguments are mathematical expressions. The primary application of expand is to distribute products over sums. This is done for all polynomials. For quotients of polynomials, only sums in the numerator are expanded --- products and powers are left alone. Expand also knows how to expand most of the mathematical functions, including sin, cos, tan, exp, and others. Examples,
> expand((x+1)*(x+2));
> expand((x+1)/(x+2));
> expand((x^2+1)^7);
We will apply expand to other types of functions in the chapter on basic functions.
Simplify. The simplify command is in some ways the opposite of the expand command. The syntax is
simplify(expr);
simplify(expr, n1, n2, ...);
simplify(expr, assume=prop);
where expr is any expression and n1 , n2,... - (optional) are names or sets or lists. Prop denotes any property, such as "real", or "positive". The simplify function is used to apply simplification rules to an expression. If only one argument is present, then simplify will search the expression for function calls, square roots, radicals, and powers. In the case of two or more arguments where the additional arguments are names, simplify will only invoke the simplification procedures specified by the additional arguments. Examples:
> simplify(4^(1/2)+3);
5
> simplify((x^a)^b+4^(1/2), power);
Factor. The factor function is in some ways the opposite of the simplify command for power. The syntax is
factor(expr);
where expr is a multivariate polynomial with integer, rational, (complex) numeric, or algebraic number coefficients.
For example consider
> f :=expand((x^2+1)^7);
:
> factor (f);
This command is remarkably handy. What will it do, if the factorization is more complicated? Consider the expression What will happen if we factor this cubic?
> factor (x^3+x^2+x+1);
But with just a dash of specific information such as the fact we are dealing with complex numbers we obtain
> factor (x^3+x^2+x+1, complex);
Maple has factored the polynomial in the complex plane. Mathematically, any quartic has a factorization into irreducible (over the field of reals) quadratics and has linear factors in the complex plane. Maple will find the quadratic factors, if it can. However if you give integers, the exactness paradigm forces Maple to that end. For example, we have
> factor(x^4+2*x^3+x^2+x+1); Here everything must be exact.
> factor(x^4+2*x^3+x^2+x+1.0); Here numerical
answers are allowed; hence Maple finds ONE irreducble quadratic and the other
factors.
> factor(x^4+2*x^3+x^2+x+1, complex); All four
complex (real) roots are
computed.
Try these commands factor(x^5+x^4+2*x^3+x^2+x+1); and factor(x^5+x^4+2*x^3+x^2+x+1, complex);
Combine. The combine function is good for grouping powers. The syntax is
combine(f, power);
Parameters: f - any expression involving powers are combined by applying the following transformations:
x^y*x^z ==> x^(y+z)
(x^y)^z ==> x^(y*z)
exp(x)*exp(y) ==> exp(x+y)
exp(x)^y ==> exp(x*y)
sqrt(-a) ==> I*sqrt(a)
a^n*b^n ==> (a*b)^n
Examples:
> combine(x^2*x^3, power);
> combine((x^z)^2, power);
Other key words in the combine function may also yield useful results. For example,
combine(f, exp);
where expressions involving exponentials are combined by applying the following transformations:
exp(x)*exp(y) ==> exp(x+y)
exp(x)^y ==> exp(x*y)
exp(x+n*ln(y)) ==> y^n*exp(x) where n is an integer
Other combine commands are combine(f, ln), combine(expr, radical), and combine(f, trig). Each has obvious connotations.
Digits. You can change the number of digits you compute with
using the Digits command. The syntax
is
where
n is the number of digits you wish to compute with. Examples
> Digits:=25;
Digits := 25
> sqrt(2.0);
1.414213562373095048801689
> 4*arctan(1.0);
3.141592653589793238462643
Set the number of digits to 1500 and execute the two commands above.
This document created by Scientific Notebook 4.0.