Question about complex numbers

14 views
Skip to first unread message

Julia Goedecke

unread,
Feb 20, 2021, 4:15:45 AM2/20/21
to Numbas Users
Hello,
I have a question: why can I have complex numbers in matrices and number types in variables, but they are not recognised in matrix entry gaps? I can see the problem with the number entry gap, as it has minimum and maximum accepted answer, and you can't compare complex numbers. So you could get around it with mathematical expression. But for matrix entry, I think it doesn't parse the complex number and comes out with NiN/NiN.

Julia 

Ulrich Goertz

unread,
Feb 20, 2021, 7:24:03 AM2/20/21
to Numbas Users
Hello,
I wrote a custom part type "Matrix of complex numbers" to get around this. I have used it in a few questions, and I think it works, but since it has not been tested thoroughly, in particular regarding the handling of errors, I do not want to "publish" it in the Numbas editor. If you want to take a look: I put the source here - you could import that and take it as the basis for your own custom part. (Please do report back if you make improvements ...)
Best regards, Ulrich

Julia Goedecke

unread,
Feb 21, 2021, 1:55:32 PM2/21/21
to Numbas Users
Thanks Ulrich, we will try it out.
Julia 

--
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/ab9c32a0-521d-425e-a99d-d914859dc1ean%40googlegroups.com.

Christian Lawson-Perfect

unread,
Mar 4, 2021, 10:17:55 AM3/4/21
to numbas...@googlegroups.com
The short reason it doesn't accept a complex number is that I haven't decided what forms of complex number to accept. My first impression is that the format should be something like this regular expression:
(a)? [+-] ((b)*?i)?
where a and b are numbers in whatever notation style is acceptable.

It gets a bit tricky when you think about scientific notation for numbers, which introduces another multiplication, so the i could be on the end: 5*10^3*i, or in the middle: 5i*10^3. I suppose you could insist that it's on the end.

The other option is to treat it as a mathematical expression, and user pattern-matching to enforce it's of the right form, but allow for terms to be rearranged.

Julia Goedecke

unread,
Mar 4, 2021, 11:58:55 AM3/4/21
to Numbas Users
It's a problem of interpreting user input, yes? Rather than a problem of data type?
Julia 

Christian Lawson-Perfect

unread,
Mar 5, 2021, 12:35:18 AM3/5/21
to numbas...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages