Mathematics: Quadratic equations in one variable.
1. |
Solving Quadratic equations in one variable. |
|
Quadratic equations in one variable are part of any basic mathematics course. Such equations have the general form:
ax2 + bx + c = 0
and may have two real solutions, one unique real solution, or no real (two complex) solutions.
|
If you are not sure how to proceed to solve this kind of equations, please have a look at a math book, or search the Internet.
|
|
2. |
Quadratic equations in one variable online exercise generator. |
|
The application randomly generates an equation of the form ax2 + bx + c = 0, and the user has to find the solutions. As complex numbers are
a more advanced math topic, you can choose not to consider such solutions (considering the equation having no solution in this case).
|
Use the following link to start the online application. For details about the Perl source code, see below...
|
|
3. |
Quadratic equations in one variable Perl script. |
|
Click the following link to download the Quadratic equations in one variable Perl
script and all other files needed to run this application on your web server. Have a look at the ReadMe.txt file, included in the download archive, for details
about the different files, and where to place them on the server.
|
The Perl script is rather long and I do not display the source code here. Just some remarks, concerning how the application works:
- The parameter $action tells the script what to do:
- init, new: initialize for a new test (default settings for init, previous test settings for new).
- start, next: generate a new equation (first question for start, all other questions for next).
- check: check user's answer.
- The test web page is generated by reading a template file and replacing all custom
tags (template lines containing a tag start with '#' and all tags are placed between '#' symbols) by the corresponding actual values. What will be
displayed on the page depends on the $action parameter, of course. When all equations are done, an evaluation grid with number of correct and false answers and
success percentage is displayed.
- The code concerning the generation of the equation is located in the generateEquation subroutine, that generates (controlled) random values for the equation
coefficients and returns the equation string, the solution type (one real root, two real roots, no solution, complex solutions) and two root values. Also, the
generated equation string is modified by the subroutine formatEquation, that ensures a proper display (correcting expressions like "0x", "-1x" or " + 0", for
example).
|
For security reasons (XSS protection), all parameters read from the form are checked to have either precise values or a given format. As example, here is my
regular expression to check if a complex number entered by the user is well a complex number (I guess that a professional Perl programmer would have found a
shorter and better expression...):
my $fcplx = '^(\d+|\d+\.\d+|-\d+|-\d+\.\d+|';
$fcplx .= '\d*i|\d+\.\+*i|-\d*i|-\d+\.\d+i|';
$fcplx .= '\d+ \+ \d*i|\d+ \+ \d+\.\d+i|\d+ - \d*i|\d+ - \d+\.\d+i|';
$fcplx .= '-\d+ \+ \d*i|-\d+ \+ \d+\.\d+i|-\d+ - \d*i|-\d+ - \d+\.\d+i|';
$fcplx .= '\d+\.\d+ \+ \d*i|\d+\.\d+ \+ \d+\.\d+i|\d+\.\d+ - \d*i|\d+\.\d+ - \d+\.\d+i|';
$fcplx .= '-\d+\.\d+ \+ \d*i|-\d+\.\d+ \+ \d+\.\d+i|-\d+\.\d+ - \d*i|-\d+\.\d+ - \d+\.\d+i)$';
|
If you want to place a link to the application on some other page, include the following into this page's HTML:
<a href="/cgi-bin/eququad.pl?action=init">Quadratic equations in one variable online application</a>
|
|
If you find this page helpful or if you like the Quadratic equations in one variable web application, please, support me and this website by signing my guestbook.