psychopy.org | Reference | Downloads | Github

Math.norm function in Javascript

I am trying to use the equivalent to np.linalg.norm (which works fine locally) to Javascript. I’m not super familiar with JS but as far as I can tell, Math.norm is an existing function, although it throws an error when I try to use it. This is how I call it:
r = Math.norm(mouse_resp_1.getPos());

Am I incorrectly using it, do I have to separately download the math library, or is there some other issue?

Edit: The error is: TypeError: Math.floor() is not a function

What is the error?

TypeError: Math.norm() is not a function

Math is a built in function that doesn’t have norm

math isn’t built in but does contain norm. Just in case, you could try math.norm() but I suspect is isn’t available.

https://mathjs.org/docs/reference/functions/norm.html

Interesting, I use other math functions (sin, cos, etc.) and they work, so I assumed the math library was built in. Maybe they are just part of PsychoJS?

Read my message again

Math is built in
math may not be

I see what you mean now! You’re right, math does not seem to be built in.

I’ve solved it by adding

to my index.html file.

Thank you @wakecarter for pointing me in the right direction!

1 Like

I haven’t edited index.html before. Exactly what line did you need to add to be able to use math?

There is an external libraries section:

1 Like