7 views

### Julia Goedecke

Feb 20, 2021, 4:15:45 AMFeb 20
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

Feb 20, 2021, 7:24:03 AMFeb 20
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

Feb 21, 2021, 1:55:32 PMFeb 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.

### Christian Lawson-Perfect

Mar 4, 2021, 10:17:55 AMMar 4
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

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