Re: Cubed roots of negative numbers

22 views
Skip to first unread message

Christian Lawson-Perfect

unread,
Jun 1, 2021, 8:57:35 AM6/1/21
to numbas...@googlegroups.com
Hi David,
I can't think of any changes that would make this start giving different answers. I've just checked out the last version of the code from 2017 and it gives the same answers.
I don't get just a real part for root(-4,3); I get 0.793700526 + 1.374729637*i.
The 'root' function returns the principal root, which means that root(x,n) is equivalent to x^(1/n). I think it's reasonable that it should return the real root, if there is one.
I've changed root(x,n) to return the negative real root if x is real and x<0.

On Tue, 1 Jun 2021 at 13:27, David Wishart <d.wi...@tees.ac.uk> wrote:
I'm getting strange results when trying to take the cube root of a negative numbers, test case below.


When I use root(negative_cubic_number,3) Numbas appears to be returning the first complex root 
root(-1,3) = 0.5 + 0.86i when I would only be interested in the real one eg -1.

On top of this however, if the question doesn't use a cubic number then it only returns the real part of the first complex root  
root(-4,3) = 0.79

Is there any reason why this could only have happened recently? I ask as the full question I have is part of SCORM test that has deployed without this issue for 4 years. Whilst there is only a 1.4% chance of the question returning a negative to deal with, I'd estimate that in the region of 1000 students could have attempted this question over that period but errors have only surfaced in the last month.

--
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/b81f20a3-2b9b-4f3f-87c2-4ec8560e308an%40googlegroups.com.

David Wishart

unread,
Jun 1, 2021, 9:39:43 AM6/1/21
to Numbas Users
Hello Christian,
Thanks for your quick reply, it works as expected now. 

It could have just been coincidence that this has just cropped now but it seemed weird that we never had any issues until last month and there's been two instances since then.

Ignore the bit about the cube root of -4, I realised after posting that my browser window was hiding the rest of the answer. I deleted the original post and put up a new one but you were that quick that you started to to reply before I'd got rid of it!

Regards
David

David Wishart

unread,
Jun 1, 2021, 10:21:32 AM6/1/21
to Numbas Users
One more thing I've just noticed is that the full complex version still shows on the variables page and although the number does get interpreted correctly for marking, this seems a bit counterintuitive when trying to check questions.

Christian Lawson-Perfect

unread,
Jun 1, 2021, 10:23:09 AM6/1/21
to numbas...@googlegroups.com
Ahh, that's because I didn't update the version of JME that the editor uses. Thanks for telling me!

David Wishart

unread,
Jun 1, 2021, 10:39:12 AM6/1/21
to Numbas Users
That works as well now thank-you.

I've noticed that this makes the behaviour of root(negative_number,3) and (negative_number)^(1/3) to be different. I'm fine either way as I can just root(x,n) for my purposes. The question below is closer to the full question that I'm trying to fix. Test_Answer and Test_Answer2 in the variables show the difference that I see.

Reply all
Reply to author
Forward
0 new messages