This shows how to use vectors in a problem.
Download file: Vectors.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');
Preamble
These standard macros need to be loaded.Context('Vector');
# Uncomment to display vectors in ijk format.
#Context()->flags->set(ijk => 1);
# Uncomment to change the appearance of the ijk vectors. This sets them to be
# overset with vector arrows, instead of bold.
#Context()->constants->set(
# i => { TeX => "\mathit{\vec i}" },
# j => { TeX => "\mathit{\vec j}" },
# k => { TeX => "\mathit{\vec k}" },
#);
$v1 = Vector('<1, 3>');
$v2 = Compute('<-3, 1>');
$v3 = 3 * i + 2 * j - 4 * k;
$v4 = Vector(1, 1, 0);
# Create an array of the components of $v3.
@v3comp = $v3->value;
$a = 3 * i + j;
# $b = $a + $v1; # this results in an error
$c = norm($v3); # vector length
$v5 = unit($v3); # unit vector in same direction
$d = $v1 . $v2; # dot product
$v6 = $v3 x $v4; # cross product
$v3->isParallel($v4); # returns 1 if parallel, 0 if skew
BEGIN_PGML
[`\vec{v}_1 = [$v1]`]
[`\vec{v}_2 = [$v2]`]
[`\vec{v}_3 = [$v3]`]
[`\vec{v}_4 = [$v4]`]
[`\vec{a} = [$a]`]
[`\vec{v}_1 + \vec{v}_2 = [$v1 + $v2]`]
[`||\vec{v}_3|| = [$c]`]
[`[$v5]`] is a unit vector in the same direction as [`[$v3]`]
[`\vec{v}_1 \cdot \vec{v}_2 = [$d]`]
[`\vec{v}_3 \times \vec{v}_4 = [$v6]`]
[`\vec{v}_3`] [@ $v3->isParallel($v4) ? 'is' : 'is not' @] parallel to
[`\vec{v}_4`]
The first element of [`\vec{v}_3`] is [@ $v3->extract(1) @]
The third element of [`\vec{v}_4`] is [@ $v4->extract(3) @]
END_PGML
Setup
Select the Vector context to work with vectors.
If vectors are to be displayed as a sum of i,
j, k components, we can set the
ijk context flag. This would result in the vector
$v1 in this example being shown as
$v1 = i + 3j instead of $v1 = <1, 3>,
for example.
If it is desired to change how the i, j,
and k vectors are displayed, say to have them displayed
with over set arrows instead of bold, the TeX formatting of those
constants can be redefined as shown in the second comment.
Vectors are defined either with the Vector or
Compute constructors, or by using the predefined vector
constants i, j and k. Any vector constructed
with i, j, and k will be a
three-dimensional vector even if the vector k is not used.
That means Vector('<1, 2>') is not equal to
i + 2j.
If a vector is defined using the constants i,
j and k, as in the definition of
$v3, then the default display of that vector will be in
i, j, k format even if the
ijk context flag is not set.
To explicitly require that the vectors be two-dimensional rather than
three-dimensional, use the Vector2D context instead of the
Vector context.
The components of vectors are available as an array returned by
$v->value. Thus, the three components of the vector
$v3 can be stored in the array @v3comp by
calling @v3comp = $v3->value. The first component can
then be accessed using $v3comp[0], the second component
using $v3comp[1], and the third component using
$v3comp[2].
To obtain a single component of a vector use the extract
method. For example, to obtain the first component of $v3
use $v3->extract(1). Note that the index of
extract starts at 1, not 0.
See the vector wiki page for more information about MathObject vectors.
BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.