Vectors
Student input
Use column_vector(1,2,3) or row_vector(1,2,3) to enter vector components. These forms
are available in every question and display using the question's matrix parentheses.
See the vector constructor reference.
These are inert expressions: they retain their row or column identity until converted to
matrices. For example, column_vector(1) and row_vector(1) remain distinct, although both
convert to matrix([1]). Before matrix arithmetic or an answer test that expects matrices,
convert the student and teacher expressions with vec_convert.
For convenience, c(...) and r(...) are aliases for column and row vectors. Enable them by
adding stack_linear_algebra_declare(true) to the question variables. For example, c(1,2,3)
then evaluates to column_vector(1,2,3). Contributed libraries that previously enabled this
notation continue to enable the aliases for existing questions.
The aliases make longer expressions easier to enter, for example
c(1,2) + s*c(3,4) + t*c(5,6) for column vectors, or
r(1,2) + s*r(3,4) + t*r(5,6) for row vectors.
Both matrix input types accept vector model answers and return the corresponding vector values. The fixed grid infers its dimensions from the answer. The variable-size input accepts whitespace-separated components without fixing their number. Vector blocks can also be used in augmented matrix inputs.
vec_convert(ex)converts vector expressions into matrices. If the terms do not conform, the original expression is returned.vec_convertedp(ex)checks that no vector constructor remains. Use it to check that an earlier conversion succeeded before continuing a PRT.un_vec_convert(ex)converts a row or column matrix to vector notation.
Vectors as single entities
It is very useful to treat vectors as a single entity. The vector stackvector(a) and the atom a are different, and are not considered algebraically equivalent. While students may type in stackvector(a) as an answer, they are likely to type in a. The teacher can either (1) add in stackvector ephemeral forms to the student's answer in the feedback variables using texboldatoms or (2) remove all stackvector forms from the teacher's answer by using the destackvector(ex) function on their answer. In the future we may have an option in the input to apply texboldatoms to students' expressions.
The display of the ephemeral form of stackvector is controlled by the function stackvectortex, e.g. you can display vectors differently using the following examples.
stackvectortex(ex):= block(sconcat("{\\bf \\vec{", tex1(first(args(ex))), "}}"));
stackvectortex(ex):= block(sconcat("{\\bf \\underline{", tex1(first(args(ex))), "}}"));
which should go in the question variables.
Any texput commands in the question variables now become "context variables" and will be available to the inputs. So, if in the context of your question you would like a variable such as x to be considered as a vector and displayed as a vector you can add one of the following to the question variables.
texput(x, "\\mathbf{\\vec{x}}");
texput(x, "\\mathbf{\\underline{x}}");
Whenever x is then displayed in any part of the question, including the student's input validation or feedback generated by the answer tests, we will have the updated tex for this atom. E.g.
texput(x, "\\mathbf{\\vec{x}}");
texput(y, "\\mathbf{\\vec{y}}");
and a student types in a*x+b*y then the tex output will be .
texboldatoms(ex)Displays all non-numeric atoms in bold. Useful for vector questions.
Inline i,j,k notation
If you are trying to use the vector notation such as you will probably want to redefine to be an abstract symbol, not a complex number.
More information on this is given under Numbers. In particular, use the question level option "Meaning and display of sqrt(-1)" value symi to stop interpreting i with i^2=-1 and return it to being an abstract symbol.
Another way to do this is to create matrices as follows:
ordergreat(i,j,k);
%_stack_preamble_end;
p:matrix([-7],[2],[-3]);
q:matrix([i],[j],[k]);
Now we can use the dot product to create the vector. The STACK function texboldatoms wraps all atomic variable names in the ephemeral function stackvector, which is typeset in bold.
v:texboldatoms(dotproduct(p,q));
If you turn the option "Multiplication sign" to none, this should display as
Notice the use of the function ordergreat. ordergreat can only be used once at the beginning of the question.
If you use the special constant %_stack_preamble_end; then anything before this constant will be available everywhere in the question, including the inputs.