 |
|
 |
Hi I use your Libary. it's very very nice code but i have still a problem i want to delet da row or a col ? i didn#t have found a soulution for this problem cya muhaa
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Paul, first, thank you for sharing your work.
Here's a sample linear system I want to solve:
49x - 7y + z = 6 25x - 5y + z = 4 9x - 3y + z = 2
How can I solve this with GeneralMatrix? I would greatly appreciate it if you could give me some sample code.
Thanks, Andy
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi I think the solve is
GeneralMatrix A like 49 -7 1 25 -5 1 9 -3 1 and GeneralMatrix B like 6 4 2
GeneralMatrix N=A.Transpose()*A; GeneralMatrix n=A.Transpose()*B; GeneralMatrix x=N.Inverse()*n
x.GetElement(0,0) is your x x.GetElement(1,0) is your y x.GetElement(2,0) is your z
i use this for solving overdetermined equation but is still work for your problem
cya muhaa
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I have a 3x3 matrix, V: V = 100 10 1 625 25 1 900 30 1
In MatLab I do the QR and get: >> [Q,R] = qr(V,0) Q = -0.0909 0.8789 0.4683 -0.5680 0.3405 -0.7493 -0.8180 -0.3341 0.4683 R = 1.0e+003 * -1.1003 -0.0396 -0.0015 0 0.0073 0.0009 0 0 0.0002
However when using the DotNetMatrix I get: Matrix Q = -0.0908856214131766 0.878886544558686 -0.468292905790847 -0.568035133832354 0.340488733969466 0.749268649265355 -0.817970592718589 -0.334104570207539 -0.468292905790847
While the values are good, the right hand column is all a negative of the MatLab results.
Any suggestions?
Regards Lachlan.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
LachlanGro wrote: While the values are good, the right hand column is all a negative of the MatLab results.
True, I have verified it. I have also used the example matrix in the wikipedia http://en.wikipedia.org/wiki/QR_decomposition[^] and the signs do not correspond.
LachlanGro wrote: Any suggestions?
I am currently looking into it, I do not have any immediate idea of the source of the problem.
Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Paul, I posted a similar question on the Jama discussion list and apparently there is no bug, its just that the solution is "not unique".
While I believe this is the case, I could not find an indication of what would be unique.
Either way I pass exactly the same data into other libraries (such as BlueBit, Matlab) and the results are fine.
Regards, Lachlan.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
LachlanGro wrote: I posted a similar question on the Jama discussion list and apparently there is no bug, its just that the solution is "not unique".
Thanks for the information.
LachlanGro wrote: While I believe this is the case, I could not find an indication of what would be unique.
Computations based on the results are valid, also the Q'Q = I, so that may be the case.
LachlanGro wrote: Either way I pass exactly the same data into other libraries (such as BlueBit, Matlab) and the results are fine.
Currently, I do not have any math package so I was only looking for books and online examples to compare. I will look into the algorithm used to see if we could get the same results as Matlab to prevent any doubt.
Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
Kuryn wrote: You should never make a class virtual.
Hmmm, I do not know about this new rule in town. However, you have the source codes, so please do whatever you like with it - it is a public domain license.
Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Well you should make a class virtual when needed. But not a mathematical class, because nothing changes different. Like in a Vector, a dotProduct is a dotProduct.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Thanks for this library, it is very useful!
I have a question: I arrive at some point with a Matrix that is singular, and I want to perform an Inverse on it.
GeneralMatrix matrixInvertQ = matrixMultiplyN.Inverse(); ...
public virtual Matrix Inverse() { return Solve(Identity(m, m)); }
The Inverse method calls Solve, which instantiates a LUDecomposition object and calls its Solve method. There it tests for singularity, and I get the "Matrix is singular" exception.
I have very limited knowledge in mathematics, so bear with me. At the point where the matrix is considered singular, shouldn't a pseudoinverse by performed? In the comments for the Inverse method, it says "inverse(A) if A is square, pseudoinverse otherwise". Is there a part missing from implementation?
Thanks!
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
Hi:
There is a bug in the svd decomposition, inherited from Jama. The problem is with the V matrix, when n>m. The correction is:
if (wantv) { for (int k = n - 1; k >= 0; k--) { if ((k < nrt) & (e[k] != 0.0)) { for (int j = k + 1; j < n; j++) { double t = 0;
The bug is reported here: http://cio.nist.gov/esd/emaildir/lists/jama/msg00430.html
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Thank you!
I'm no math guy but I have a question upon another thing (may be a "bug"?):
The SVD is A[mxn] = U[mxm]*S[mxn]*V[nxn]^T - so U should be a square matrix. But it is defined here as:
m = Arg.RowDimension; n = Arg.ColumnDimension; int nu = System.Math.Min(m, n); U = new double[m][]; for (int i = 0; i < m; i++) { U[i] = new double[nu]; }
Shouldn't it be like this:
m = Arg.RowDimension; n = Arg.ColumnDimension; int nu = System.Math.Min(m, n); s = new double[System.Math.Min(m + 1, n)]; U = new double[m][]; for (int i = 0; i < m; i++) { U[i] = new double[m]; }
|
| Sign In·View Thread·PermaLink | 4.40/5 |
|
|
|
 |
|
 |
Hello everybody,
I am new using matrix in C# and I would like to thank and congratulate to the author of General Matrix. This is a very usefull and easy class to work with it.
Currently I am working with the SVD descomposition to obtain the PseudoInverse... But it doesn't work. The code blocks during the SVD calculation. Does anybody have the same problem?
Thanks in advance
|
| Sign In·View Thread·PermaLink | 2.67/5 |
|
|
|
 |
|
 |
Hi there, I encountered two problems when solving under-determined equation systems: The first problem is an ArrayIndexOutOfBoundsException when trying to get the S-Matrix. I think the problem is the wrong size of S, because of A[mxn] = U[mxm]*S[mxn]*V[nxn]' the dimensions should be m-by-n but in the code they are n-by-n:
virtual public GeneralMatrix S { get { GeneralMatrix X = new GeneralMatrix(n, n); double[][] S = X.Array; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { S[i][j] = 0.0; } S[i][i] = this.s[i]; } return X; } }
Then there is a problem with the dimension of the singular values vector in the constructor of SingularValueDecomposition:
s = new double[System.Math.Min(m + 1, n)];
For example, my equation system has six equations and eight variables, so m=6 and n=8. Then s will be the size of seven and there will be a singular value that doesn't really exists.
In addition to this, I get different results when using the svd-function of Matlab. The singular values and the U-matrix are exactly the same, but in the V-matrix the last n-m coloumns have different values, the others have the same like in Matlab. But I didn't find a suitable place in the code for that problem.
Please correct me, if I understood something mathematically wrong.
modified on Friday, August 29, 2008 10:16 AM
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Not sure this discussion board is still active, but I recently discovered this library and found it extremely useful, so first of all thanks very much for making it available!
Unfortunately, I have also discovered problems with the SVD computation, and wrong dimensions of the resulting matrices.
If you do a test with the example provided on Wikipedia[^], this library produces wrong results as far as I can tell (FWIW, Matlab returns the same values given on Wikipedia).
After running the example (an SVD on a 4-by-5 matrix), the S matrix from the SVD object is a 5-by-5 matrix, whereas the correct result should be a 4-by-5 matrix. Also, the entries of the U and V matrix seem to be in the wrong order and/or have the wrong sign.
Also, the singular values vector returned by the SVD object has five elements in this example, but, according to Wikipedia
"An m × n matrix M has at least one and at most p = min(m,n) distinct singular values." so there should be a maximum of four singular values, not five.
If anyone is still following this board, I'd very much like to hear whether anyone can confirm my findings and/or has a bug fix! I'd really like to use this library for my work, but only if works with non-square matrices.
Thanks! Martin
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have problem with relation between eigenvalues and eigenvectors. My eigenvectors do not correspond with their eigenvalues. Instead they are mixed (for exaple eigenvalue a1 has vector v3, instead of v1). All eigenvalues i have are negative so can that be problem?
Thanks
Cukaric
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
sergiomad wrote: Is available a method for getting the Karhunen-Loève vectors?
No, Karhunen-Loève is not directly related to matrix.
sergiomad wrote: but I can't find methods like "times()"
This port uses the .NET naming, it should be "Multiply(...)"
Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
public GeneralMatrix(double[] vals, int m) { this.m = m; n = (m != 0?vals.Length / m:0); if (m * n != vals.Length) { throw new System.ArgumentException("Array length must be a multiple of m."); } A = new double[m][]; for (int i = 0; i < m; i++) { A[i] = new double[n]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { A[i][j] = vals[i + j * m]; } } }
I think the statement
A[i][j] = vals[i + j * m];
should be revised as
A[i][j] = vals[j + i * m];
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Sorry for the late response. Well, not a bug. If you see the documentation of that constructor, vals is said to be packed by columns.
I think you needed the "packed by row" array filling, I kept the original implementations. I will update this library soon and give the user the options to choose between the two with an extra parameter to avoid confusion.
Best regards, Paul.
-- modified at 11:32 Tuesday 17th July, 2007
Jesus Christ is LOVE! Please tell somebody.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Paul, I am new to DotNet programming and I'm working on a project to determine whether a series of values over time are trending upward, down or steady. I'm working with performance data from the Windows OS. I believe the simplest approach will be to run a least squares analysis on the data (40 points, each from a successive day). I would like to use your DotNetMatrix library but am a little out of my league. Do you have any script samples/instructions for implementing the library and especially for a least squares analyis.
Thanks for your help, Tom
P.S. Love your message postscript, my brother.
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Tom,
You have many options for least squares, although I'm unsure how to use this particular library for the job (it didn't do the QR decomposition as I expected ... I never got the expected Q matrix for some reason).
Anyway, here is a least squares solution using QR decomposition (sometimes called QR Factorization). Feel free to look up least squares on Wiki as well. Also, I give links to a much easier way of doing least squares at the end of this message.
http://www.alkires.com/teaching/ee103/Rec8_LLSAndQRFactorization.htm[^]
You can get QR decomposition and linear equation solvers which actually do work (they seem to be based on LAPACK) from here:
http://www.alglib.net/matrixops/general/qr.php routine, which seems to have come from LAPACK CGEQR
and
http://www.alglib.net/linequations/general/lu.php
Both of the links above have code samples and test code that seems to work.
**** However, you may want something much simpler, such as ... ****
http://www.codeguru.com/forum/showpost.php?p=1139483&postcount=2[^]
or
http://www.pdc.kth.se/training/Tutor/MPI/Pt2pt.Lab/least-squares.c[^] (some adaptation required since this is C code, but it should be easy to adapt).
All the best, --Ralf
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |