numbas / Numbas

A completely browser-based e-assessment/e-learning system, with an emphasis on mathematics
http://www.numbas.org.uk
Apache License 2.0
202 stars 117 forks source link

An "is scalar multiple of x" function for vectors and matrices #792

Closed christianp closed 2 years ago

christianp commented 3 years ago

This would be a nice function to have, instead of having to rewrite it each time I write a question that needs it.

u is a scalar multiple of v if there is a scalar k such that u = k*v. You could find this k by computing the ratio u_i / v_i for each non-zero component i, then check that the ratios are all equal. This should work similarly to isclose, allowing given relative and absolute tolerances.

The function would look like is_scalar_multiple(u, v [, rel_tol] [, abs_tol])

Zero is an edge case: its only scalar multiple is zero.

ldnljcksn commented 3 years ago

Hello! I don't see anyone assigned to this issue, so would it be helpful for me to work on this function? Thank you!

christianp commented 3 years ago

HI @ldnljcksn, thanks for offering! Please have a look at our guidance on contributing code. The maths functions are defined in runtime/scripts/math.js, and JME functions are defined in runtime/scripts/jme-builtins.js.

Open a pull request when you've got something I can look at, and please ask for help if you get stuck.

alisahq commented 2 years ago

Hello Christian @christianp,

I fixed this issue and initiated a pull request. Would you mind if you take a look at it and give me some feedback?

900

Thanks so much and I appreciate your help!

Best, Alisa

christianp commented 2 years ago

I forgot to close this! Thanks again, @alisahq