HP Forums
SVD - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: SVD (/thread-67.html)



SVD - jgreenb2 - 12-13-2013 08:17 PM

I can't seem to get SVD to work for non-square matrices. This works perfectly on the 50g but fails on the Prime...unless I'm doing something wrong. Anyone else seen this?


RE: SVD - Mark Hardman - 12-13-2013 08:40 PM

On the latest firmware:

\[ SVD\left ( \begin{bmatrix} 1 & -1 \\ 1 & -1 \\ \sqrt{3} & 0 \end{bmatrix} \right ) \]

Gives "Error: Bad Argument Type" in both Home and CAS.

Looks like a definite bug to me.

Mark Hardman


RE: SVD - Mark Hardman - 12-13-2013 09:16 PM

If it is a bug, it is a minor bug.

Try entering the SVD command in lowercase:

\[ \textrm{simplify} \left ( \textrm{svd}\left ( \begin{bmatrix} 1 & -1 \\ 1 & -1 \\ \sqrt{3} & 0 \end{bmatrix} \right ) \right ) \]

Gives a result of:

\[ \begin{bmatrix} 0.5477 & 0.7071 & -0.4472 \\ 0.5477 & -0.7071 & -0.4472 \\ 0.6325 & 5.1840 \times 10^{-17} & 0.7746 \end{bmatrix} \]

Mark Hardman


RE: SVD - jgreenb2 - 12-13-2013 09:34 PM

Mark,

Thanks. How did you think to do this? The toolbox menu inserts in uppercase and the manual defines SVD in uppercase. Did you just try at random or is there some logic to when this matters?

Also, using SVD() (uppercase) on a square matrix seems to work...very odd!


RE: SVD - Mark Hardman - 12-13-2013 09:44 PM

Search the old forum archives. The difference between UPPERCASE/lowercase for commands on the Prime has already generated several other bug reports. It is a matter of confusion that the Prime Team will hopefully address in a future release.

Mark Hardman


RE: SVD - jgreenb2 - 12-13-2013 10:03 PM

Thanks, I'll check it out. I admit I want to like this calculator but it's been a bit of a trial so far!


RE: SVD - parisse - 12-15-2013 10:04 AM

The current algorithm covered only square real matrices (as you can guess, implementing numeric algorithms is not my main business, and giac/xcas uses LAPACK for svd, therefore it was only required here), svd was also sometimes able to return an answer for rectangular matrices. I'm improving it, it will handle rectangular real or complex matrices that are well conditionned (0 or small singular values will not be handled, I'm not writing a dedicated numerical algorithm for that, just reusing existing routines).


RE: SVD - jgreenb2 - 12-15-2013 03:42 PM

Parisse,

Thanks for the clarification. Nice to know these things are being worked out. As long as there's a reasonable error message for ill-conditioned matrices I'll be happy Smile

It would also be nice if it worked correctly in RPN: svd() should take a matrix from the stack and just push U, S, V back onto the stack.

--jeff


RE: SVD - parisse - 12-16-2013 09:22 AM

Actually, you don't really need a message for ill-conditionned matrix, just look at the ratio between the largest singular value and the smallest one in s.