0

I have used this code to produce quadratic equations, is there a way to make the solutions real and solvable for lower levels?

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

\newcommand*{\Difficulty}{10}%

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

\begin{document}  
    \QuadraticEquations{3}
\end{document}

1 Answer 1

1

Instead of randomizing the coeficients of a quadratic equation Ax²+Bx+C, you should randomly choose the roots, thus they will be real as you demand.

In order to restore the expanded form of a quadratic equation, knowing its roots, you need to use Vieta's theorem.

enter image description here

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

\newcommand*{\Difficulty}{10}%

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

\begin{document}
  
\begin{itemize}
    \QuadraticEquations{3}
\end{itemize}

\end{document}

Notice that I'm using \pgfmathprintnumber[showpos]{...} in order to print plus sign in case the coefficient is positive (when it's negative, minus sign prints by default).

1
  • Thanks that works great
    – Paul A
    May 13, 2022 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .