Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add dynamic math to webpage

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>&#8290;</mo>
   <mi>x</mi>
  </mrow>
  <mo>+</mo>
  <mn>12</mn>
 </mrow>
</math>
like image 596
Bill Avatar asked Oct 23 '10 14:10

Bill


2 Answers

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):

  1. app retrieves a random formula_problem from database (either any type, or of a certain type)
  2. app assigns randomly generated numbers to constants, i.e. "b = 1, m = 2, y = .5"
  3. app swaps constants in formula_solution with numbers from step 2 (inside {} so easy to find)
  4. app solves for x and encrypts answer (in the case of the quadratic, there are 2 answers, Split("{split}") into array)
  5. app displays to web browser and asks student to solve: "y = mx + b" and "b = 1, m = 2, y = .5"
  6. app also puts encrypted answer in a hidden form field on the web page
  7. student solves for x, then types answer into text box, and clicks submit button
  8. app compares student's solution with decrypted hidden solution
  9. 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)

like image 176
JohnB Avatar answered Oct 11 '22 02:10

JohnB


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

like image 24
Michael Goldshteyn Avatar answered Oct 11 '22 01:10

Michael Goldshteyn