0

I am having a very strange error. If the built in factorial function is used on an array, for example factorial([1,2]) I receive the error maximum recursion limit of 500 reached. This is running on a mac with 2014 Matlab. Running 2017 on a windows has no problem. I thought maybe factorial wasn't set up to evaluate vectors on earlier versions, but then I ran it on a 2012 version on ubuntu and it evaluates it fine. I've done some googling and haven't found this error related to factorials. Does anybody have any idea what is happening?

To be clear, it is doing it on very small numbers, like my [1,2] example. I could understand the error, I guess, if it was trying to evaluate the factorial of a large number.

  • It might not be correctly vectorized. If it's checking whether `[1, 2] == 0`, `[0, 1] == 0`, `[-1, 0] == 0` and so on. It definitely sounds like a bug if it only comes up on one platform. – Andrew Sep 06 '17 at 21:37
  • 2
    What does the following show you when typed into the command window?: `which factorial -all` – gnovice Sep 06 '17 at 21:42
  • Try to use the matlab debugger. – m7913d Sep 07 '17 at 07:16
  • @AndrewPiliser, I'm afraid I don't understand that, why would it be trying to check that? To gnovice, the computer is at home, I'll try it when I get back. To the world, I can't help but wonder why the question got a down vote... – Fractal20 Sep 07 '17 at 18:25
  • @Fractal20 They might have implemented a naive algorithm like [the recursive example here](https://stackoverflow.com/a/5721830/879997). If you translate that to Matlab and plug a vector in, you'll never hit the base case. Or it could be some other bug. If you can verify with `which factorial -all` that it's calling the built in function, you might need to upgrade from 2014. – Andrew Sep 07 '17 at 19:01

0 Answers0