reddit / emacs

Can calc find the minimum norm least-squares of a matrix?

AlchemicRez · 2022-04-06 17:08
This question may not be posed correctly because I'm very new to linear algebra and I'm asking based on my limited understanding. Basically matlab / [https://octave-online.net/](https://octave-online.net/) appears to automatically compute the multiplicative inverse of a non-regular matrix using " the minimum norm least-squares solution" described on this page: [https://www.mathworks.com/help/matlab/ref/mldivide.html](https://www.mathworks.com/help/matlab/ref/mldivide.html) I want to know if emacs calc can do that or if there is a package that might help me out. I know the easy answer to this solution is to use matlab or octave-online, which I've done and that works; however I'd like to use emacs for this if possible. If this isn't currently available it's not the end of the world. I'm just learning as I go. Thanks in advance. Edit: I very much appreciate the tips and references provided here (I'm following up on everything here). Even though I provided Google with many incantations beforehand, I had no idea of some of these and I'm excited to proceed. I'm learning this material at work where a group of mentors are sharing their knowledge on their own free time. Very cool of them. And very cool of everyone here who provided great advice.
[deleted] · 2022-04-06 17:51
[removed]
wintergreen_plaza · 2022-04-06 19:34
Lol, rude… I wouldn't call generalized inverses "basic," especially for someone very new to linear algebra, and MATLAB has great documentation that often includes helpful examples. I don't know enough about `calc` to address the original question, but since it sounds like an example of the [XY Problem](https://en.wikipedia.org/wiki/XY_problem), I suggest that OP look up "right matrix inverse." A quick summary would be, you want to solve: >A\*x = B, for x, but A isn't an invertible square matrix. However, if A\*A' (that is, the matrix A multiplied by its transpose) is invertible, then see that >x = A'\*(A\*A')^(-1)\*B is a solution to the original equation: >A\*\[A'\*(A\*A')^(-1)\*B\] = (A\*A')\*(A\*A')^(-1)\*B = I\*B = B. We call R=A'\*(A\*A')^(-1) the "right inverse" of A, because A\*R=I. This isn't the only way to solve the original equation, which is why MATLAB was careful to specify that it chooses the solution with least norm. The MATLAB page says that for non-square matrices, it uses a QR solver, which would generalize the method above. I suspect this is what u/fragglestickcar0 intended for you to implement yourself.
edumerco · 2022-04-06 19:40
OP said he/she is new in the topic and your response is demoralizing instead of encouraging. You are also failing in seeing the positive in OP's behavior: made it's need clear as much as could, gave adequate references and established a clear priority for the other people in the community to decide when/how to invest their effort. We all make mistakes. We all start in/with ignorance and still are ignorants in many fronts. No one knows everything. It's our duty to share kindly whatever we have so others can make it better. If you are not interested in giving understanding and support, I kindly ask you to stop making negative prophesies based on insufficient information or at least refrain from doing harm. Thanks a lot. ----- *If you want to go fast, go alone.* *If you want to go fast, let's go together.* (anonymous african proverb)
jsled · 2022-04-06 19:50
This has been removed, as it is not very civil; please attack ideas, not people. This is a warning. If you persist in being rude to users here who are asking questions, you will be banned.
fragglestickcar0 · 2022-04-06 19:57
>This isn't the only way to solve the original equation, which is why MATLAB >was careful to specify that it chooses the solution with least *Cue Nathan Thurm: I know that, don't you think I know that?* Correct, and while I haven't looked at calc's solver, I'll bet you dollars to doughnuts OP wasn't interested in pseudoinverses.
markasoftware · 2022-04-06 20:52
You may like to try https://emacs.stackexchange.com/a/59147/23538. It won't give you the answer directly, but by concatenating the X column vector on the right of A and then reducing to RREF, it is fairly easy to then read off a solution if one exists.
karthink · 2022-04-06 20:54
There isn't a built-in command for this. However you can use the Penrose pseudoinverse formula pinv(A) := A' * inv(A * A') for this in calc. 1. Type in your matrix and store it in a variable A. 2. Type in `A` and press RET a couple of times. 3. `V J` will find the conjugate transpose of A 4. `*` will multiply entries on the stack 5. `&` or `V &` will invert a square matrix. You can combine these to get pinv(A). My advice is to stick to MATLAB or Octave for linear algebra. As you can see Calc can get unwieldy for extended calculations very quickly.
Soupeeee · 2022-04-07 01:59
If you want a computing package in emacs, you can try Maxima, which is the original symbolic computation library and handles linear algebra fairly well. It ships with a repl implementation that's really nice to use within emacs. https://maxima.sourceforge.io/
IWant2rideMyBike · 2022-04-07 09:15
You could install matlab or [GNU octave](https://www.gnu.org/software/octave/index) on your system and use it from org-mode via [org-babel](https://orgmode.org/worg/org-contrib/babel/intro.html): [https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave-matlab.html](https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave-matlab.html)