Creating an equation library (Updated 03-FEB-2017)
|
01-15-2015, 12:50 AM
(This post was last modified: 01-15-2015 01:29 AM by Snorre.)
Post: #21
|
|||
|
|||
RE: Creating an equation library (updated)
Hello,
Not an answer to why complex elements in the first matrix: just observed that the second vector element is nearly zero, so the complex elements have no impact on L1(1)*diag(L1(2))*TRN(L1(3)). Seems like a floating point rounding issue in the imaginary part calculation of Σ which translates to some really bad error in U, so that it isn't unitary anymore (L1(1)*trn(L1(1))=trn(L1(1))*L1(1)=identity doesn't hold). |
|||
01-15-2015, 02:06 AM
(This post was last modified: 01-15-2015 02:12 AM by Han.)
Post: #22
|
|||
|
|||
RE: Creating an equation library (updated)
(01-15-2015 12:50 AM)Snorre Wrote: Hello, Maybe the algorithm uses 1/s_i * A * v_i where s_i is the i-th eigenvalue and v_i is the corresponding eigenvector (perhaps this is why the corresponding column of U is all complex -- but I can't seem to make the results match this...) Another way to get non-diagonal matrices is to compute the orthonormal eigenvectors of A^T * A and of A * A^T, for which the Prime does not seem to introduce complex values. The problem is that for non-square matrices additional steps may be needed to ensure that the eigenvectors are orthogonal (usually Gram-Shmidt takes care of this). Still, that's a lot of additional work that should have been automatically handled by SVD... :-( Graph 3D | QPI | SolveSys |
|||
01-15-2015, 02:55 AM
(This post was last modified: 01-15-2015 03:04 AM by Snorre.)
Post: #23
|
|||
|
|||
RE: Creating an equation library (updated)
Hello Han,
by making your matrix containing only reals (just change the very first element from 3 to 3.) you won't get complex results. This new result is real but the first matrix is not orthogonal again (maybe a minor bug or -- worse -- just a numerically instable svd). |
|||
01-15-2015, 04:20 AM
Post: #24
|
|||
|
|||
RE: Creating an equation library (updated)
(01-15-2015 02:55 AM)Snorre Wrote: Hello Han, I'm unable to make this happen; changing 3 to 3. still shows up as 3 in Home view; in CAS view it still gives me the same complex results (as well as Home). I use standard notation for the number format, if that makes any difference. Graph 3D | QPI | SolveSys |
|||
01-15-2015, 04:25 AM
Post: #25
|
|||
|
|||
RE: Creating an equation library (updated)
In GIAC/XCAS: evalf(SVD([[3,4.5,4.5],[4.5,12.25,1.25],[4.5,1.25,12.25]]))
no problems with complex elements in the U matrix, but the V matrix has all zeros in column 3 (in Wolfram alpha, for this example U equals V). The Sigma matrix, containing the singular values, is the same. |
|||
01-15-2015, 05:30 AM
Post: #26
|
|||
|
|||
RE: Creating an equation library (updated)
(01-15-2015 04:25 AM)Helge Gabert Wrote: In GIAC/XCAS: evalf(SVD([[3,4.5,4.5],[4.5,12.25,1.25],[4.5,1.25,12.25]])) Hm... that's clearly a bug in giac/xcas; for symmetric matrices the SVD should be essentially the same as an eigen-decomposition (up to a few nuances with signs of eigenvalues and corresponding eigenvectors). Graph 3D | QPI | SolveSys |
|||
01-15-2015, 10:30 AM
Post: #27
|
|||
|
|||
RE: Creating an equation library (updated)
Hello Han,
(01-15-2015 04:20 AM)Han Wrote: I'm unable to make this happen; changing 3 to 3. still shows up as 3 in Home view; in CAS view it still gives me the same complex results (as well as Home). I use standard notation for the number format, if that makes any difference.Forgot to mention: that's possible by entering the matrix in CAS or do a approx([[...]]). But you're right. It doesn't make any difference. I did a mistake (luckily didn't clear the history): I've introduced some invisible roundoff deviation by Sorry. That won't help you. |
|||
01-16-2015, 02:44 AM
(This post was last modified: 01-16-2015 02:47 AM by Han.)
Post: #28
|
|||
|
|||
RE: Creating an equation library (updated)
Looks like the SVD command uses EIGENVV to obtain the matrix V and to determine the diagonal matrix of eigenvalues. Letting M0 be the matrix I mentioned earlier, then EIGENVV(M0*trn(M0)) gives
Code: M0:=[[3,4.5,4.5],[4.5,12.25,1.25],[4.5,1.25,12.25]]; The result: Code: { So the middle eigenvalue for M0*trn(M0) is a negative value. Take the square root and you get the eigenvalue found from doing SVD(M0). Note that the real part was dropped (likely due to roundoff). (−7.5863407865E−32)^.5 = 1.48466797577e−30+2.75433127755e−16*i I wonder if within the SVD algorithm, forcing the diagonal matrix from the eigen-decomposition to have all positive entries (they necessarily have to be, since they are supposed to be squares), would provide a quick fix for this issue. There is, of course, always the option of writing our own SVD... Graph 3D | QPI | SolveSys |
|||
01-16-2015, 04:30 PM
Post: #29
|
|||
|
|||
RE: Creating an equation library (updated)
I hope the SVD algorithm will be checked by Bernard Parisse and HP, especially since it appears that XCAS is affected.
(Of course, SVD, being numerical in nature, is designed to be used in Home, so maybe not). |
|||
01-16-2015, 04:35 PM
Post: #30
|
|||
|
|||
RE: Creating an equation library (updated)
(01-16-2015 04:30 PM)Helge Gabert Wrote: I hope the SVD algorithm will be checked by Bernard Parisse and HP, especially since it appears that XCAS is affected. I have a sneaky suspicion it will be fixed :-). Graph 3D | QPI | SolveSys |
|||
01-18-2015, 08:07 PM
Post: #31
|
|||
|
|||
RE: Creating an equation library (updated)
To create this eq library, is required a function that solves nonsquare systems (more unknowns than equations) to be devised an algorithm that recursively solving I think I saw one HPCalc
|
|||
01-19-2015, 01:21 AM
(This post was last modified: 01-19-2015 01:22 AM by Han.)
Post: #32
|
|||
|
|||
RE: Creating an equation library (updated)
(01-18-2015 08:07 PM)compsystems Wrote: To create this eq library, is required a function that solves nonsquare systems (more unknowns than equations) to be devised an algorithm that recursively solving I think I saw one HPCalc The plan is to use Newton's method (which is iterative). Each set of equations is transformed into functions \(\vec{F} = \langle f_1, f_2, \dotsm, f_m \rangle^T \). Applying Newton's method to solve \( \vec{F}(\vec{x}) = 0 \) would require the Jacobian. Snorre posted an example in this thread. In order to solve for \( \vec{x} \), we use SVD. This will take care of all cases, but one would have to properly interpret the solutions. SOLVESYS uses a similar scheme, but does not seem to use SVD or even LSQ for overdetermined systems. Graph 3D | QPI | SolveSys |
|||
01-19-2015, 01:52 AM
(This post was last modified: 01-21-2015 04:45 PM by compsystems.)
Post: #33
|
|||
|
|||
RE: Creating an equation library (updated)
Another option is to create a version SVD, I extracted the source code of (SVD MathTools TI 89) With tiedit http://home.arcor.de/p-engels/tiedit/
/!\ © = COMMENT TM = TRANSPOSE Code: SVD(mm) MathTools Guide http://www.ibiblio.org/technicalc/packag...hTools.pdf ///////// PD: A help from the community would be create a form to add equations, as doing FORMULAPRO for TInspire calculators FormulaPro Project Home Page http://tiplanet.org/forum/viewtopic.php?t=9576 FormulaPro Creator Home Page http://education.bwns.be/FormulaPro/ |
|||
10-29-2015, 10:46 AM
(This post was last modified: 10-29-2015 01:30 PM by Han.)
Post: #34
|
|||
|
|||
RE: Creating an equation library (updated)
So the equation library was put on hold until I could get a working SVD that was a little more robust than the built-in one. The one suggested by compsystems is not numerically stable. We use the SVD to compute the pseudo-inverse of the Jacobian matrix in Newton's method, and then a backtracking linesearch to find a suitable step size. Solving \( J \cdot \Delta \mathbf{x} = - \mathbf{F} \) can be done (quicker) using other matrix factorizations (such as QR or LU) and perhaps I will add the option to choose later on. For now, though, the pseudo-inverse from the SVD seems the most robust, albeit the slowest of them all.
There is also a backtracking linesearch as implemented in SOLVESYS from the HP48 days. One can read more about it from Numerical Recipes -- The Art of Computer Programming, 3rd ed, sections 9.6 and 9.7. The messages from root finding have the same meaning as in SOLVESYS (e.g. "Zero" means the solver found an \( \mathbf{x} \) such that \( \lVert \mathbf{F} \rVert_2 < \epsilon \) for some suitable tolerance \( \epsilon \). These messages need further fine tuning in cases of ill conditioned matrices and ill posed problems. I do not intend to keep the current interface -- it's too clunky and just does not look as nice as it could. There are also plans to switch over to app format so as to take advantage of AFiles for data storage (e.g. storing the equations and possibly pictures/diagrams) so that everything is kept together. Right now, all equations must be saved in a Note name "EqLib" (see earlier posts). Here's the current work in progress for those who want to tinker with an equation library / solvesys program. In order for this to work, please read earlier posts on setting up the "library data" in a note named "EqLib" and make sure to also install the SVD program found here: http://www.hpmuseum.org/forum/thread-4976.html Code: #pragma mode( separator(.,;) integer(h32) ) Edit: for the sake of completeness, here is a sample EqLib Note file: Code: { Graph 3D | QPI | SolveSys |
|||
11-13-2015, 03:20 PM
Post: #35
|
|||
|
|||
RE: Creating an equation library (updated)
The next version will likely make use of the Solve app and that the end result would be a mix of an equation library (a la HP48) and SolveSys (for both HP48 and HP49). The choice of basing the next version on the Solve app is that the Symb view would allow one to view all the equations in textbook form. That said, there are some caveats with this idea:
1. Variables would have to be created first. This can be done easily as the user would simply be asked to enter a list of variable names, and their creation would be done by the app. While it is possible to simply create equations without specifying the variable names (and have the app create them where necessary), we would be limited to algebraic input and display of said equations. (In the Symb view, one cannot enter an expression/equation involving non-existent variables). For equations that involve complex expressions, I find that being able to view them using textbook display to be more advantageous than not having to specify the variables of a system. 2. We are limited to only 10 expressions/equations using the Symb view. This limitation is only in the viewing of the equations. The system would be stored internally by the app, and there would be mechanisms to "page" through all the equations in a system having more than 10 equations. I have not run into too many instances of systems involving more than 10 equations except in the case of regressional analysis (curve fitting data to a formula). In the latter case, all the equations would look essentially the same, though. Once a user sets up the variables and equations, there will be options to the "save" the system and add it into one's "library" of equations. Then, users can either create a new system, or select from their library. If anyone has other ideas they'd like to propose, please let me know. Graph 3D | QPI | SolveSys |
|||
11-13-2015, 08:05 PM
Post: #36
|
|||
|
|||
RE: Creating an equation library (updated)
Looks great!
One comment: Will there be an option to solve for a variable in C vs. restricting it to R (e.g., with a checkbox [Cmplx On/Off], kind of like SolveSys)? |
|||
11-13-2015, 10:01 PM
(This post was last modified: 11-13-2015 10:09 PM by Han.)
Post: #37
|
|||
|
|||
RE: Creating an equation library (updated)
(11-13-2015 08:05 PM)Helge Gabert Wrote: Looks great! Yes, even the current solver handles complex solutions (or at least it should). If it doesn't then there's probably some place where dot products aren't using conjugates properly. CAS dot product is different from Home dot products. Graph 3D | QPI | SolveSys |
|||
11-13-2015, 10:16 PM
Post: #38
|
|||
|
|||
RE: Creating an equation library (updated)
Thanks - - it seems to work now - - still have to test it a little bit more.
|
|||
11-13-2015, 10:54 PM
Post: #39
|
|||
|
|||
RE: Creating an equation library (updated)
(11-13-2015 03:20 PM)Han Wrote: The next version will likely make use of the Solve app and that the end result would be a mix of an equation library (a la HP48) and SolveSys (for both HP48 and HP49). The choice of basing the next version on the Solve app is that the Symb view would allow one to view all the equations in textbook form. That said, there are some caveats with this idea: As I was reading your suggestions it seemd you were reading on my mind. Your targets are perfect, a hybrid of fast inserting or pre-defined collection of equations. Wonderful. This program would be considered one of my top- rated Hp program ever (with Vigag, FEM and Secciones). I´ll stay tuned for your release. Thank you Han for your great work. |
|||
11-14-2015, 02:24 AM
Post: #40
|
|||
|
|||
RE: Creating an equation library (updated)
So, in order to obtain the same DOT() result in CAS as in Home,
in CAS only, one has to call DOT(CONJ([vector_1]),[vector_2]); with complex elements in vector_1, in order to negate the complex conjugates which otherwise arise. A bug? |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)