How to match functions in mathematical expressions

13 views
Skip to first unread message

Chris Jobling

unread,
May 2, 2021, 4:20:02 AM5/2/21
to Numbas Users
This has had me pulling my hair out!

I am writing questions on the Fourier transform which uses the Dirac delta function \delta(t) and \delta(\omega).

If I use math expression and have a question something like:

Q: What is the inverse Fourier transform of the unit step function?

A: 2pi*delta(omega) - 2i/omega

The prompt and feedback that students see is nicely formatted as
latex("2\pi\delta(\omega) - \frac{2i}{\omega}")

But the marking algorithm complains that delta looks like a multi character function but is not defined. Even if I change this to d(omega) I get a complaint about the function d(...) not being defined.

Is there a way to incorporate arbitrarily named functions in mathematical expressions?

Thanks

Chris Jobling
Swansea University

Christian Lawson-Perfect

unread,
May 2, 2021, 10:30:32 AM5/2/21
to numbas...@googlegroups.com
Hi Chris,
The standard marking algorithm for mathematical expression parts establishes whether the student's answer is equivalent to the expected answer by evaluating them both on a randomly selected set of values for the free variables. If there are any undefined functions in either expression, this can't be done.
Occasionally it makes sense to just not do this check, for expressions where you want the answer in a very specific format, but the other way to get round it is to define the function. You could define delta(x) as a custom function in the question, and then the marking would work.


--
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/58b37599-b5e9-43f5-a5ee-53c995fa1adcn%40googlegroups.com.

Chris Jobling

unread,
May 3, 2021, 7:58:06 AM5/3/21
to Numbas Users
Thanks Christian. That's great and clarifies the workings of mathematical expressions for me. I was sure that there must be a way to define new functions, but completely overlooked Extensions -> functions.

Another quick off-topic question, can j be used for the imaginary number i?  And does I have to be in the numerator of an imaginary fraction? I've tried to enter 1/(iomega) [or 1/(jomega as we electrical engineers usually write it] but couldn't get the marker to mark it properly.

Christian Lawson-Perfect

unread,
May 4, 2021, 6:06:45 AM5/4/21
to numbas...@googlegroups.com
You can't use j as the imaginary unit at the moment. I have an open issue about this at https://github.com/numbas/Numbas/issues/691.
You're missing a multiplication symbol in your example. 1/(i*omega) would work. If you want to allow students to omit the multiplication symbol, or even a space, you could tick the box "Force single-letter variable names?" in the Restrictions tab - see https://docs.numbas.org.uk/en/latest/question/parts/mathematical-expression.html#term-force-single-letter-variable-names

Reply all
Reply to author
Forward
0 new messages