How to add dynamic math to a web page

I am a math teacher who wants to insert some kind of dynamic math into a website. What I would like to achieve is to press a button that a student can click to randomly change a question so that he asks the same type of question, but with different numbers. For example,

The coefficient of a quadratic expression is of the form ax ^ 2 + bx + c, where a = 1, and b and c are positive integers from 1 to 100 and such that the roots are real integers.

If I use MathML to encode mathematics (like the markup below) stored in a database (like MySQL), how can I set things up so that the computer automatically and randomly changes the mathematical expression to as I described above? I don't know much about server-side scripts ... can I achieve this with PHP? Or would it rather be client-side JavaScript? I'm just looking for tips to help me choose a learning path. Thanks 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>&#8290;</mo> <mi>x</mi> </mrow> <mo>+</mo> <mn>12</mn> </mrow> </math> 
+7
math mathml
source share
7 answers

One way is to save the general formulas in your database, i.e. the example you specified ax^2 + bx + c . An example 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 + bb{split}m{split}y graph x = ({b} - {y}) / -1*{m} 3 etc etc etc etc 

Then (psuedocode):

  • application retrieves random formula_problem from database (any type or specific type)
  • the application 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)
  • the application solves for x and encrypts the response (in the case of quadratic answer 2, Split("{split}") into an array)
  • displays the application in a web browser and asks the student to decide: "y = mx + b" and "b = 1, m = 2, y = .5" Application
  • also places the encrypted response in a hidden form field on the web page.
  • the student decides for x, then enters the answer in the text box and presses the submit button
  • The application compares the student’s decision with the decrypted hidden solution.
  • displays the application for the web browser: "right / wrong" along with the 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. Processing can be performed on the server side in one of the above languages ​​or, as soon as the data (formula) is retrieved from the database, processing can be performed on the client side of JavaScript.

This question is very open, because there are many approaches that a developer can take, and it comes down to preference. My personal opinion is that it would be more difficult to program some of these materials on the client side on the JavaScript side or on the server side C # or PHP.

If you already know any computer languages, that is, C ++, then select a scripting technology that looks the same and start learning by reading books and online tutorials / code samples.

(sorry, but I'm not a mathematician)

+3
source share

Well, you can use javascript and random numbers to change the odds. Take a look at the following webpage to get a good lesson on how to do this:

JavaScript: Random Scripts

+1
source share

I would try Google Math (TeX) formulas . It will be much cleaner.

You can do it server side, if you understand javascript, php is not that difficult.

Only values ​​/ type of expression (a, b, c) should be stored in the database so that you do not store files of a specific representation in db. I would make a generator that creates the values ​​a, b, c and stores them in db.

+1
source share

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> 
+1
source share

You can, of course, do this in PHP on the server side. PHP has built-in libraries for parsing XML, which should be good in your case. It is easy to just randomize a, b and c, but to always have a real answer, you should use some other algorithm to generate numbers. Since you are a math teacher, I think you are as good as anyone who finds such an algorithm.

I think you should divide the work into several parts:

  • Extract the question from MySQL (this is easy)
  • Parse MathML (maybe you can find a library for this?)
  • Random number generation

The last one is the most difficult, especially if you need a common system. How does the computer know what answer you are looking for? Perhaps you need a specific algorithm for different types of questions, because sometimes you need a complex number, and sometimes you need a sine wave. For each question, you may need to resolve a different approach on your behalf.

There are (more or less) general algorithms for solving, for example. polynomial equations. You probably know some of the approaches that already exist in your profession. Maybe such an algorithm can be used? I think you will find that most of the hard work is actually the math involved in this project, not the coding.

Be prepared that a common system may not be possible.

+1
source share

it doesn’t matter whether this is done on the server or on the client side. Usually, I prefer to do some processing on the client side, since for each student this should be random, there is no reason to add server processing time to it.

How do you read from a MySQL database? You can easily work with the data returned from this side of the server script. Regarding the implementation of this, I would suggest a jQuery plugin that should be very easy to use: jQuery xmlObjectifier

Then the stream: The Excersize student page loads and requests the mathml xml object, after returning from mysql, dynamically loads the xml, converts it to a js (json) object, and then randomizes the object data. Upon completion, he loads the product into the container on the student’s page.

+1
source share

You might want to consider WeBWorK , the MAA-administered homework management system. It is designed by mathematicians and for mathematicians as a home-based online home system, and it is quite popular. Of course, it is also a lot more product than you ask.

0
source share

All Articles