VectorOperations1
Vector Operations
This PG code shows how to extract the components of a constant vector, take dot and cross products of vectors, find the length of a vector, construct a unit vector, and check whether the student's answer is parallel to or in the same direction as another vector.
- Download file: File:VectorOperations1.txt (change the file extension from txt to pg when you save it)
- File location in NPL:
FortLewis/Authoring/Templates/VectorCalc/VectorOperations1.pg
| PG problem file | Explanation |
|---|---|
|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "parserVectorUtils.pl", "unionLists.pl", ); TEXT(beginproblem()); |
Initialization:
We load |
Context("Vector");
$U = non_zero_vector3D(-9,9,1);
$V = non_zero_vector3D(-9,9,1);
# value works only for vectors of constants
@Uarray = $U->value;
$Ucomp2 = $Uarray[1];
$UdotV = $U . $V;
$UcrossV = $U x $V;
$Vlength = norm( $V );
$Vunit = unit($V);
#
# Prevent students from entering the dot and
# cross products, and the vector functions
# norm and unit.
#
Context()->operators->undefine(".","><");
Context()->functions->disable("Vector");
|
Setup:
We use |
Context()->texStrings;
BEGIN_TEXT
Suppose \( \vec{u} = $U \) and \( \vec{v} = $V \).
\{ BeginList('OL', type=>'A') \}
$ITEM The second component of \( \vec{u} \) is
\{ ans_rule(20) \}
$ITEMSEP
$ITEM \( \vec{u} \cdot \vec{v} = \)
\{ ans_rule(20) \}
$ITEMSEP
$ITEM \( \vec{u} \times \vec{v} = \)
\{ ans_rule(20) \}
$ITEMSEP
$ITEM \( \left|\left| \vec{v} \right|\right| = \)
\{ ans_rule(20) \}
$ITEMSEP
$ITEM Enter a unit vector in the direction of \( \vec{v} \).
\{ ans_rule(20) \}
$ITEMSEP
$ITEM Enter a vector parallel to \( \vec{v} \).
\{ ans_rule(20) \}
$ITEMSEP
$ITEM Enter a vector in the same direction as \( \vec{v} \).
\{ ans_rule(20) \}
\{ EndList('OL') \}
END_TEXT
Context()->normalStrings;
|
Main Text: |
$showPartialCorrectAnswers = 1; ANS( $Ucomp2->cmp() ); ANS( $UdotV->cmp() ); ANS( $UcrossV->cmp() ); ANS( $Vlength->cmp() ); ANS( $Vunit->cmp() ); ANS( $V->cmp( parallel=>1 ) ); ANS( $V->cmp( parallel=>1, sameDirection=>1 ) ); |
Answer Evaluation:
In the last two answers we set flags for checking whether the student's answer is parallel to or in the same direction as the correct answer. Notice that both flags |
Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;
COMMENT('MathObject version.');
ENDDOCUMENT();
|
Solution: |
