Ntuple

Description

Accepts an ordered of numbers or formulas separated by commas. Intended primarily for coordinates of points and vectors.

Notes

Examples

\begin{question}{Ntuple}
\qutext{Find the intersection of the lines $y=x+1$ and $y=2-x$.}
% Separate the entries of the answer with commas, and parentheses
% should be included:
\answer{(-1/2,1/2)}
% Note that the response "-1/2,1/2" would also be graded as correct.
\end{question}
\begin{question}{Ntuple} 
% This question uses algorithmic variables.
\qutext{Find the exact solution of the following system of equations: 
\begin{align*} 
\var{a}x+\var{b}y&=\var{e}\\
\var{c}x+\var{d}y&=\var{f}
\end{align*} 
\\
Your answer should be an ordered pair $(x,y)$.} 
\answer{(\var{ans1},\var{ans2})}
% Note: The 'amsmath' package is needed to use the 'align' environment.
\code{$aa = range(2,6);
      $b = range(2,6);
      $c = range(2,6);
      $d = range(2,6);
      $e = range(2,6);
      $f = range(2,6);
      $det1 = int($aa*$d-$b*$c);
      $a = int(if($det1,$aa,$aa+1));
      $det = int($a*$d-$b*$c);
      $x = int($e*$d-$f*$b);
      $y = int($a*$f-$c*$e);
      $ansx = $x/$det;
      $ansy = $y/$det;
      $ansxint = int($x/$det);
      $ansyint = int($y/$det);
      $detabs = int(abs($det));
      $xabs = int(abs($x));
      $yabs = int(abs($y));
      $numx = int(if(lt($ansx,0),-$xabs,$xabs));
      $numy = int(if(lt($ansy,0),-$yabs,$yabs));
      $ans1 = if(eq($ansx,$ansxint),"$ansxint","$numx/$detabs");
      $ans2 = if(eq($ansy,$ansyint),"$ansyint","$numy/$detabs");}
% The above code chooses random integer coefficients a, b, c, d, e,
% and f. a is modified if necessary so that the determinant of the
% system will be nonzero. The solution is then calculated using
% Cramer's Rule. Finally, care is taken to display the answer
% coordinates correctly.
\end{question}