I want to create a math problem-solution sheet. The coefficients a
, b
, c
must be assigned on the fly at random so the generated pdf will show a numeric quadratic equation rather than a symbolic quadratic equation. Note a
must not be zero.
\documentclass{article}
\begin{document}
\section{Problem}
Let \(x_1\) and \(x_2\) be the roots of \(a x^2 +bx +c=0\). Find \(x_1x_2\).
\section{Solution}
\[
x_1x_2=\frac{c}{a}
\]
\end{document}
Please kindly make the solution get automatically simplified. For example: \frac{c}{a}=3
when a=2
and c=6
.
Actually the real case is more complex than this one. Not only the equations must be generated at random, but also the associated graphic plots that I write in PSTricks.
I chose Paulo's answer because using Maxima as the computation engine is very very great idea. Other answers are also good and creative, especially Altermundus'.
Best Answer
This is a partial solution and probably it's not what you want. However, I'm posting it solely for record purposes, in case anyone would need it. =)
I'll use Maxima:
First of all, I created a script file named solve.cmd in my working directory:
I'm not in my Linux box right now, but a .sh file is similar.
Using Jake's code, I added a call to this script:
I tried to use Maxima's
plot2d
function together with the call, but I failed to fix a minor error with file extensions. I intended to create apng
plot withgnuplot
and include it. Sorry, it didn't work yet.Don't forget to use the
--shell-escape
or--enable-write18
flag.EDIT: It gave me a tremendous headache, but I guess I found a nice improvement. =)
I edited the solve.cmd file in my working directory to look like this:
Now the tricky part, the LaTeX code:
Let's check the code: first of all, we run
solve.cmd
, which outputs both equation and solution to a file namedproblem.txt
. Then we create a\newread\myread
and open this file\openin\myread=problem.txt
. Now we map the first line to\theequation
(which is the equation which we defined in our Maxima code) and the second line to\thesolution
(same logic). Then we call it when needed.Again, probably some of my Maxima code is faulty. But I hope you get the idea behind this. In case of changing the equation or solution to a inline version, we may probably do some
sed
in it and replace the pattern. =)