Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My objective is to be able to generate worksheets in categories like:

  1. Laws of Indices
  2. Simultaneous Linear equations and
  3. Quadratic equations

When I say generate is to generate for example 20 different problems. I believe I have addressed that with:

 \newcommand{\questiontype}[1]{%
 \foreach \i in {1,...,#1}
 {
 \item $my question type$
 }}

Somehow I believe that it is related to the question Creating random problems by using rand option.

The only difference is the restrictions that would be needed in code. For example, considering quadratic equations, there are three categories that is problems with equal roots, distinct and imaginary.

I am not an expert in pgf nor the random parameters. I am in the learning process here and I hope you the experts can assist me. I got the inspiration from Calculs et Programmation.

I haven't developed any code as yet but am ready to learn.

EDIT

To better understand my question see the code below.

For example:

 \usepackage{lcg,calc,ifthen}

 % Une variable qui va servir
 \newcounter{det}

 \newcommand{\randomsys}{
 % Génerer 6 entiers dans [-20,20]
 \reinitrand[first=-20, last=20, counter=a] \rand
 \chgrand[counter=b] \rand
 \chgrand[counter=c] \rand
 \chgrand[counter=d] \rand
 \chgrand[counter=e] \rand
 \chgrand[counter=f] \rand
 % Remplacer 0 par 1000
 \ifthenelse{\value{a}=0}{\setcounter{a}{1000}}{}
 \ifthenelse{\value{b}=0}{\setcounter{b}{1000}}{}
 \ifthenelse{\value{d}=0}{\setcounter{d}{1000}}{}
 \ifthenelse{\value{e}=0}{\setcounter{e}{1000}}{}

 % Un énoncé selon la valeur du dét
 \setcounter{det}{\value{a}*\value{e}-\value{b}*\value{d}}
 \ifthenelse{\value{det}=0}%
 {Expliquer pourquoi le système suivant 
 n'admet pas une unique solution :}%
 {Résoudre le système suivant :}
 \[
 \left\lbrace \begin{array}{rcl} 
 \thea x+\theb y &=& \thec \\
 \thed x+\thee y &=& \thef
 \end{array} \right.
 \]}

 \randomsys \randomsys \randomsys \randomsys
 \randomsys \randomsys \randomsys \randomsys

The code above should generate random simultaneous equations. Thus my objective is to understand what each line is saying, an alternative to this like using the pgfmath from tikz, and what each definition in the code means.

Ultimately I want to learn how I can create random problems based on the above principle. The above topics mentioned (laws of indices, quad equations and simultaneous equations) are just samples to reference from.

share|improve this question
1  
This looks like quite an open-ended question. It isn't clear what would constitute a good answer to this question. Could you make it clearer what you are asking? A good start would be to explain why the answer you linked to doesn't solve your problem and to show us what you have tried so far. –  Seamus Jan 24 '12 at 18:22
    
I want to learn how to use the pgf features or an explanation of these features and their implementation. –  azetina Jan 24 '12 at 18:27

1 Answer 1

up vote 8 down vote accepted

Without more details I don't know how to help any more than this. Here is an explanation of what is going on:

  1. I define \newcommand*{\Difficulty}{10}. This number is used to determine the range of the random numbers that are generated. In this case with it set to 10, the random numbers will be real numbers in the range 1...10.

  2. \pgfmathtruncatemacro is used to set a macro with the integer value of the computed expression. So \pgfmathtruncatemacro{\DenomDifficulty}{2*\Difficulty} set the macro \DenomDifficulty to be twice that of the value specified in \Difficulty. Similarily, \pgfmathtruncatemacro{\Neum}{random(\Difficulty)} set the macro \Neum to the value returned by random(\Difficulty). Since random() provides a real valued random number from 1..10 and (assuming here) we only want integer numbers, this necessitated the use of \pgfmathtruncatemacro, instead of the usual \pgfmathsetmacro.

  3. Similarly for the \LinearSystem and \QuadraticEquations macros, it is just a matter of generating more random numbers and using them in the math expressions.

  4. You mention in your question that there are three cases for quadratic: equal roots, distinct and imaginary. If you want to only generate equations sets of equations that have the same type of roots you would need to provide an algorithm for ensuring that type of root.

    If you do not require a restriction of integer values then this is fairly simple case. For example to get equal roots you could just randomly generate \A, \B and then use \C = (\B*\B)/(4*\A). However this won't necessarily be an integer, so you'd have to include extra logic here of that is desired.

enter image description here

Further Improvements:

  • Complete macros to generate only quadratic equations with distinct real and imaginary roots.
  • Generate negative numbers as well. In this case it would be advisable to include some logic so that we do not end up with + - as in the linked to example in the question. One way would be just to generate another random number from 0..1 and use a - sign instead of a + sign (or no sign as in the leading numbers) if the random number generated was greater than 0.6 (assuming you wanted approximately 40% of the questions to have negative signs, which also controls the level of difficulty dependent on the grade level).
  • Automatically convert decimals to reduced fractions. For this refer to this question from the future Random quadratic equation, which enhances the solution presented here.

Code:

\documentclass{article}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{tikz}

\newcommand*{\Difficulty}{10}%

\newcommand{\FracQuestion}[1]{%
    \foreach \i in {1,...,#1}{%
      \pgfmathtruncatemacro{\DenomDifficulty}{2*\Difficulty}%
      \pgfmathtruncatemacro{\Neum}{random(\Difficulty)}
      \pgfmathtruncatemacro{\Denom}{random(\DenomDifficulty)}
      \item $\dfrac{\Neum}{\Denom}$%
    }%
}%

\newcommand{\LinearSystem}[1]{%
    \foreach \i in {1,...,#1}{%
      \pgfmathtruncatemacro{\Xa}{random(\Difficulty)}%
      \pgfmathtruncatemacro{\Ya}{random(\Difficulty)}%
      \pgfmathtruncatemacro{\Za}{random(\Difficulty)}%
      \pgfmathtruncatemacro{\Xb}{random(\Difficulty)}%
      \pgfmathtruncatemacro{\Yb}{random(\Difficulty)}%
      \pgfmathtruncatemacro{\Zb}{random(\Difficulty)}%
      \item $\begin{cases}\begin{aligned}%
                \Xa x + \Ya y &= \Za \\%
                \Xb x + \Yb y &= \Zb \\%
              \end{aligned}\end{cases}$%
    }%
}%

\newcommand{\QuadraticEquations}[1]{%
    \foreach \i in {1,...,#1}{%
      \pgfmathtruncatemacro{\A}{random(\Difficulty)}%
      \pgfmathtruncatemacro{\B}{random(\Difficulty)}%
      \pgfmathtruncatemacro{\C}{random(\Difficulty)}%
      \item $\A x^2 + \B x + \C = 0$%
    }%
}%

\newcommand{\QuadraticEquationsEqualRoots}[1]{%
    \foreach \i in {1,...,#1}{%
      \pgfmathtruncatemacro{\A}{random(\Difficulty)}%
      \pgfmathtruncatemacro{\B}{random(\Difficulty)}%
      \pgfmathsetmacro{\C}{(\B*\B)/(4*\A)}%
      \item $\A x^2 + \B x + \C = 0$%
    }%
}%



\begin{document}
\section{Random Fractions:}
\begin{enumerate}
  \FracQuestion{3}
\end{enumerate}
%
\section{Random 2x2 Linear Equations:}
\begin{enumerate}
  \LinearSystem{3}
\end{enumerate}
%
\section{Random Quadratic Equations:}
\begin{enumerate}
  \QuadraticEquations{3}
\end{enumerate}
%
\section{Random Quadratic Equations (Equal Roots):}
\begin{enumerate}
  \QuadraticEquationsEqualRoots{3}
\end{enumerate}
\end{document}
share|improve this answer
1  
Thanks for the quick reply. Your elaborate explanation does answer my question and does target my goal of understanding more the use of rand and pgfmath. I suppose that the restrictions can be set by using the appropriate mathematical concepts. I must reiterate that I want to understand how to typeset the code and what parameters I can play around with. Essentially, what can also help me is some literature or reference to some further reading. I don't know whether to say that this is for advanced users or not. Thanks a lot. –  azetina Jan 24 '12 at 19:48
    
If something in my explanation is not clear let me know. As far as reading material: I'd recommend reading the TikZ & PGF manual. The only way to learn it is by using it. You should also separate the issues of using random numbers from typesetting the code. The solution here was in no way intended as an example of how to typeset this material, just on how to use random numbers. I just used what you had for typesetting and expanded on that. –  Peter Grill Jan 24 '12 at 20:38
    
I will take your advice seriously. I am still learning these stuff so technical help like what you provide does help me see and understand other perspective to issues that may arrise in the futre. I am glad with the effort you put in explaining the code. –  azetina Jan 24 '12 at 22:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.