I'm doing a small project and I've encountered a problem while using Mathematica. I should mention that I'm kinda new to this software, so maybe it's just something I haven't grasped yet.
Anyway, I have a 9x9 matrix P and a 9D vector q0Dot.
Evaluating
projected = P.q0Dot
ended up taking a very long computational time. My laptop is quite powerful, but after I waited for like 10-15 minutes, I aborted the evaluation. I was kinda expecting slow evaluation, since the computational time of products is not linear.
So I reverted to calculate one element at a time, like:
a = P[[1, All]] . q0Dot
and so on (just one is enough for the sake of this post).
Now, the problem I've encountered is that a (and other elements of the result vector) is not a 9D vector, as it should be. is not a scalar.
I don't think it's related to the fact that Mathematica doesn't treat lists as row or column vectors. Correct me if I'm wrong.
To show what happened:
Dimensions[P]
Dimensions[q0Dot]
Dimensions[a]
{9, 9} {9} {8}
Note that almost every element of P cointains sine and cosine expressions and is fairly complicated.
So I was wondering what the problem is and made a couple of theories, but have found out nothing so far.
- maybe one element (maybe the last one) was null, so it got ignored at the end, but that's not the case;
- maybe the computational time is exceeding the maximum allowed and it stops computing without a warning, but I don't really know how to check that;
- maybe there's some Mathematica behaviour I don't know about
I'd be really really grateful if any of you could point me out at the solution!
EDIT:
I'm adding my code, which I didn't do at first because I thought it would have been too detailed for the post itself. Also, it's making use of an external library, which I'm adding too.
My code + library - Google Drive
Now: it's an Inverse Kinematics problem, dealing with an industrial robotic arm.
The matrix P (along with the others) contains only sines and cosines, but quite an amount, since it has 9 variables.
Unless you're doing something considerably more complicated than just having a dot product of integers or Reals, It should be super fast to calculate
In fact, I've tried that and didn't encounter any problems, as morbo stated.
Now I'm a bit confused. P . q0Dot should be a 9D vector, since it's a 9x9 matrix multiplied by a 9D (column) vector. As all of you stated, multiplying one row of P, which is a 9D (row) vector, by q0Dot should result in a scalar.
Well, blame my stupidty for this one, since I made a gaffe (which I'm going to highlight): maybe I didn't focus enough, since this should be obvious, duh.
So why isn't it? Now I'm concerned about two things: one, is why that doesn't result in a scalar; two, what kind of computation Mathematica did to achieve that 8D result. Which may be the same problem in my case.
I think this is everything you asked for, to improve my question. If not, I'll surely add some more!
Do[Print[n, " ", Timing[projected = Take[P, {1, n}, {1, n}].Take[q0Dot, n]][[1]]], {n, 9}]to see the increase in timing and where it gets bogged down. – Somos Mar 16 '19 at 23:48