L-7 MCS 320 Wed 7 Sep 2005
| > | restart; |
1. Basic Data Types
The basic data types are numbers: integers, rationals, floats, strings, etc.
| > | a := 3; |
| > | b := 3.0; |
| > | whattype(a); whattype(b); |
The type determines the effect of the operations.
| > | a + 10^(-20); b + 10^(-20); |
| > | s := "x*y + 3*x^3 - 8"; |
| > | whattype(s); |
| > | p := parse(s); # opposite to convert(p,string) |
2. Expression Trees
Let us look into the structure of the polynomial p. The p is an expression, a composite data type.
| > | op(p); whattype(p); nops(p); |
We see that p is of type "+" and p consists of 3 operands.
| > | p1 := op(1,p); # select the first operand of p |
| > | op(p1); whattype(p1); |
| > | p2 := op(2,p); op(p2); whattype(p2); |
| > | op([2,2],p); # x^3 is the 2nd operand of the 2nd operand of p |
| > | op([2,2,1],p); op([2,2,2],p); whattype(op([2,2],p)); |
| > | r := convert(p,`*`); # we convert p from a `+` to a `*` |
| > | op(r); |
| > | q := convert(r,`+`); |
3. Attributes
Attributes are characteristics of a variable what a user can add to it. It is mainly for human consumption, we could see it as an annotation or a comment to a variable.
| > | p := x^2 + x + 1; |
| > | alias(alpha=RootOf(p)); |
| > | whattype(alpha); |
To associate to alpha the meaning as a formal root we can add a string as an attribute to alpha:
| > | alpha := setattribute(alpha,"a formal root of x^2 + x + 1"); |
| > | attributes(alpha); # query the attributes of alpha |
4. Properties
A property of a variable is used mainly for simplication purposes in calculations. Unlike attributes, we use properties for calculating more efficiently, which means in symbolic computation that we may simplify more often.
| > | assume(x,real); |
| > | simplify(sqrt(x^2)); |
Maple does the simplification because of the assumption, which is indicated by the flag x~.
5. Units
Units give meaning to calculations.
| > | convert(1,units,km,miles); |
| > | evalf(%); |
| > | with(Units[Standard]); |
Warning, the name Unit has been rebound
Warning, the assigned names factor and polar now have a global binding
Warning, these protected names have been redefined and unprotected: *, +, -, /, <, <=, <>, =, Im, Re, ^, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate, convert, cos, cosh, cot, coth, csc, csch, csgn, diff, eval, evalc, evalr, exp, expand, floor, frac, int, ln, log, log10, max, min, mul, normal, root, round, sec, sech, seq, shake, signum, simplify, sin, sinh, sqrt, surd, tan, tanh, trunc, type, verify
![]()
![]()
![]()
| > | a := 3*Unit(miles); |
| > | b := 7*Unit(km); |
| > | c := a+b; |
| > | evalf(c); |
After loading Units[Standard], Maple automatically converts to the metric system.