I'm a math teacher wanting to insert some dynamic math into a website. What I'd like to achieve is to have a button that a student can press to randomly vary a question so that it's the same type of question, but with different numbers. For example,
Factor the quadratic expression of the form ax^2 + bx + c, where a = 1, and b and c are positive integers between 1 and 100, and such that the roots would be real whole numbers.
If I'm using MathML to encode the math (e.g., like the markup below), stored in a database (e.g., MySQL), how could I set things up so that the computer automatically and randomly varies the math expression in the way I described above? I don't know much about server-side scripting... could I achieve this with PHP? Or would this be more a job of JavaScript on the client side? I'm just looking for some advice to guide my choice of study path. Thank you
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<mrow>
<mn>7</mn>
<mo>⁢</mo>
<mi>x</mi>
</mrow&开发者_开发问答gt;
<mo>+</mo>
<mn>12</mn>
</mrow>
</math>
One way is to store generic formulas in your database, i.e. the example you gave ax^2 + bx + c
. Example of database called formulas
:
id_formulas formula_problem constants type formula_solution
1 ax^2 + bx + c = 0 a{split}b{split}c polynomial x = (-1*{b} + ({b}^2 - 4*{a}*{c}) ) / 2*{a} {split} x = (-1*{b} - ({b}^2 - 4*{a}*{c}) ) / 2*{a}
2 y = mx + b b{split}m{split}y graph x = ({b} - {y}) / -1*{m}
3 etc etc etc etc
Then (psuedocode):
- app retrieves a random
formula_problem
from database (either any type, or of a certain type) - app assigns randomly generated numbers to constants, i.e. "b = 1, m = 2, y = .5"
- app swaps constants in
formula_solution
with numbers from step 2 (inside{}
so easy to find) - app solves for x and encrypts answer (in the case of the quadratic, there are 2 answers,
Split("{split}")
into array) - app displays to web browser and asks student to solve: "y = mx + b" and "b = 1, m = 2, y = .5"
- app also puts encrypted answer in a hidden form field on the web page
- student solves for x, then types answer into text box, and clicks submit button
- app compares student's solution with decrypted hidden solution
- app displays to web browser: "correct/incorrect" along with correct answer
This web application can be written in Java/C#.NET/VB.NET/PHP/any web technology. The database can be SQL Server/MySQL/PostgreSQL/XML/etc. The processing can all be done server side in one of the aforementioned languages, or, once the data (formula) is retrieved from the database, the processing could be done in client side JavaScript.
This question is very open ended because there are many approaches that a developer could take, and it comes down to preference. My personal opinion though is that it would be harder to program some of this stuff in client side JavaScript versus server side C# or PHP.
If you know any computer languages already, i.e. C++, then pick a scripting technology that looks similar and start learning by reading books and online tutorials/code examples.
(sorry I'm not a math guy though)
Well, you can use javascript and random numbers to vary the coefficients. Have a look at the following web side for agood lesson on how to do this:
JavaScript: Random Scripts
I would try the Google Mathematical (TeX) Formulas. It will be a lot cleaner.
You can do it server side if you understand javascript, php isn't that hard.
The database should only be storing the values/type of expression (a,b,c) you don't to store presentation specific stuff in the db. I would make a generator that creates values a,b,c and store them in the db.
You can certainly do it in PHP on the server side. PHP has built-in libraries for XML parsing which should be good in your case. It's easy to just randomize a, b & c but to always have a real answer you must use some other algorithm to generate the numbers. Since you're a math teacher I think you are as good as anyone in finding such an algorithm.
I think you should split the work up into different parts:
- Fetch a question from MySQL (this is easy)
- Parse the MathML (maybe you can find a library to do this?)
- Generating the random numbers
The last one is the hardest, especially if you want a generic system. How do the computer know what sort of answer you are looking for? Maybe you need specific algorithm for different types of questions, because sometimes you do want a complex number, and sometimes you need a sinus wave. Each question may need to be solved by a different approach on your behalf.
There are (more or less) generic algorithms for solving e.g. polynomial equations out there. You do probably know some of the approaches already in your profession. Maybe such an algorithm can be used? I think you will find out that most of the hard work is actually the mathematics involved in this project, not the coding.
Be prepared that a generic system may not be possible.
it shouldn't matter much whether to do it server or client side. I usually prefer to do any sort of processing on the client side since it should be random for each student there is no reason to add processing time of the server for this.
How do you read from the MySQL database? You could easily work with the data returned from that server side script. As to how to go about implementing it I'd suggest a jQuery plugin that should be very easy to use: jQuery xmlObjectifier
The flow is then: Student Excersize page loaded and requests the mathml xml object, after returning it from mysql it dynamically loads the xml, transforms it into a js object (json) and then performs randomization on the object's data. Upon finishing it then loads the product into a container on the student page.
something like this might help :
<html>
<?php
//if the button has been pressed
if(isset($_POST['click'])){
//generate a random number from 1 - 5 and store it in $random
$random = rand(1,5);
//query the database for the equation with the id of $random
$result = $mysql_query("select equation from questions where id=$random");
$row = mysql_fetch_row($result);
//print the equation
echo $row[0];
}
?>
<form method="post" action="">
<input type="submit" name="click" value="go"/>
</form>
</html>
You might want to consider WeBWorK, a homework management system now administered by the MAA. It's designed by and for mathematicians as an online homework system, and it's quite popular. Of course, it's also quite a lot more product than you're asking for.
精彩评论