Question: Polynomials extension, create "polynomial" from student's answer

8 views
Skip to first unread message

Ulrich Goertz

unread,
Apr 8, 2021, 4:24:33 PM4/8/21
to Numbas Users

Hi, I would like to have students enter a polynomial, and to create an instance of the JME polynomial type provided by the Polynomials extension. (Specifically, I want to ask my students to "Find a polynomial that annihilates the following matrix." I wrote some JME functions to evaluate a polynomial on a matrix, but I need to get my hands on the polynomial entered by the student, to use it in my custom marking algorithm, and failed to do so, so far.)

I see there is a JavaScript from_string method in polynomials.js, but I am not sure how to reach out to that. I'd be grateful for any suggestions ... Thanks!

Best regards, Ulrich

Christian Lawson-Perfect

unread,
Apr 12, 2021, 4:51:21 AM4/12/21
to numbas...@googlegroups.com
There wasn't a straightforward way of constructing a polynomial from a string in JME. I've fixed that. Now you can call for example polynomial("x^2+3x+2").
While I was doing that, I noticed that the equality test for polynomials didn't properly cope with zero coefficients, so I've fixed that too. The polynomials extension hasn't been very rigorously tested, so please be careful when using it with student input, and let me know if you spot any more bugs or missing features.


--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/numbas-users/54c5e448-cb6b-47da-b314-8ec25c039a14n%40googlegroups.com.

Ulrich Goertz

unread,
Apr 23, 2021, 2:09:26 PM4/23/21
to Numbas Users
Thanks, Christian, that's very helpful!
I used the extension for several problems and am happy with it :-)

One thing that I wasn't able to do in a completely straight-forward way is to retrieve a LaTeX representation of a polynomial in a JME function. (I need this in the advice section of this problem on the euclidean algorithm in the polynomial ring over the rationals.) For now, I worked around this by adding a JavaScript function which takes a polynomial p and returns p.toLaTeX(); This feels a bit like a hack. Maybe I am missing something? In any case, it's not an actual problem for me, it's more a question of making the polynomials extension more user-friendly.

Christian Lawson-Perfect

unread,
Apr 26, 2021, 9:21:26 AM4/26/21
to numbas...@googlegroups.com
Good point! I've added functions `string(p)` and `latex(p)` which produce plain string and LaTeX renderings of a polynomial.

Reply all
Reply to author
Forward
0 new messages