> with(linalg):
Warning, the protected names norm and trace have been redefined and unprotected
> u := [1, 2, 3];
> f := t-> [t, t^2, t^3];
> g := t -> [cos(t), sin(t), t];
> h := t -> [cos(t), sin(2*t)];
To add vectors or multiply them by scalars, you can do this directly, or use the Maple evalm and scalarmul commands. These give equivalent though not identical result.
> t^4*u+2*f(t)-g(t);
> evalm(t^4*u+2*f(t)-g(t));
> u*t^2;
> scalarmul(u,t^2);
The individual components of a vector are also available in Maple, as shown below. You can use this to extract the individual functions for plotting or further manipulation.
> u[3];
> f(t)[1];
> g(t)[2];
The linalg package has procedures for the dot product and the cross product. The latter procedure, however, works only on vectors with three components and the former procedure requires two vectors with the same number of components, so beware. Some examples are shown below.
> innerprod(u,f(t));
> crossprod(u,g(t));
> crossprod(f(t),g(t));
> f := x-> x^2 - 4*x + 3;
> g := x -> x^2 - 4.062*x + 3.02;
Suppose one wants to find the roots of f and g. The easiest way to do this in Maple is with some form of the solve command. For f, it is clear that there are exact roots:
> solve(f(x)=0,x);
The above command solves f(x) = 0 for the variable x. For g, on the other hand, an exact solution seems unlikely. Here solving using floating point (numerical) arithmetic is more helpful:
> fsolve(g(x)=0,x);
Now recall the basic syntax for the two Maple differentiation commands: diff and D:
> diff(f(x),x);
Notice that diff differentiates expressions like f(x) rather that functions such as f. The command D, on the other hand, differentiates functions and the result is also a function:
> D(f);
Since D(f) is indeed a function, it can be directly evaluated, while diff(f(x),x) being an expression implies that it can only be evaluated using the subs command:
> D(f)(3);
> subs(x=3, diff(f(x),x));
Finally, please note that the command evalf forces the numerical (floating point) evaluation of something that Maple by default does not evaluate:
> Pi;
> evalf(Pi);
Written by:
JDF
(E-Mail: bach@wpi.edu)
Last Updated: Monday, 22 September 2003
Copyright 2001, Joseph D. Fehribach