Bug inverting matrices - Inverting a matrix gives inconsistent answer - Messages
File not found.File not found.File not found.
Best regards.
Alvaro.
When you say one of the versions, you mean 'K^-1 =' vs 'Kinv = K^-1; Kinv = '. If it was a condition number problem, would you expect that to show up simply because we've defined a variable rather than evaluating without a new variable definition? I'm just specifically confused as to why:
K^-1 = one answer
Kinv = K^-1; Kinv = a different answer.
Is something happening related to the condition number when saving the inverse as a variable that doesn't happen when evaluating directly?
Thanks again for your thoughts.
What I say about eval() is about an SMath function that make some round-up and truncation errors. In your case you need to check if you get the same different result with KK := submatrix(K,1,20,1,20) and KK := eval( submatrix(K,1,20,1,20) )
Finally, your K matrix is of the type 'sparce'. Some programs can detect that and use some specific algorithms for such cases, like matlab.
Best regards.
Alvaro.
PD. Perhaps the condition number requires some explanation. Suppose you solved a purely resistive electrical circuit by direct calculation, either nodes or meshes. If you see it from a simple theoretical point of view, you could have used Kramer's rule to solve it, since it is a linear system. And you know well that for there to be a unique solution, the determinant of the matrix of the system has to be different from zero. But we are talking about a real circuit. And the resistors are not exact, they come with a 10% error, for example. So how do I know if the circuit I designed is going to be stable or a mess? You justify by calculating some of the condition numbers to the system matrix. So you say that the problem you solved is well conditioned because you got a low value for that number, which is going to indicate that there are going to be no problems using that matrix in a linear system. That is, you never provide only one solution to a practical problem. You also have to study its stability. Condition numbers are suitable for linear systems with matrices. For differential equations there are also methods to study the stability of the proposed solutions.
WroteThanks, Alvaro. I've attached a screenshot of part of the K matrix in case that will spark any thoughts, but not sure if that will be helpful. I could upload the .sm file as well if that would be easier.
When you say one of the versions, you mean 'K^-1 =' vs 'Kinv = K^-1; Kinv = '. If it was a condition number problem, would you expect that to show up simply because we've defined a variable rather than evaluating without a new variable definition? I'm just specifically confused as to why:
K^-1 = one answer
Kinv = K^-1; Kinv = a different answer.
Is something happening related to the condition number when saving the inverse as a variable that doesn't happen when evaluating directly?
Thanks again for your thoughts.
Hi David,
From my point of view, your matrix looks like a stiffness matrix from a Finite Elements Method approach, if that is the case, I was working on that some time ago, and I found some issues trying to solve the equation [x]=[K]^-1*[F]. My solution was to use Gauss elimination or a solver for a banded version of [K].
Anyway, as mention Alvaro, it would be great if you attach your .sm file to check it.
Best,
Oscar
WrotePlease, attach the document, mostly the matrix creation.
Page3 MatrixForum.sm (46 KiB) downloaded 51 time(s).
WroteHere's a demo showing the differences.
MatrixInversionError_Demo.sm (56 KiB) downloaded 64 time(s).
Hi. The attached shows how using eval for get the same inverse matrix in both cases.
MatrixInversionError_Demo.pdf (170 KiB) downloaded 62 time(s).
MatrixInversionError_Demo.sm (197 KiB) downloaded 58 time(s).
Best regards.
Alvaro.
WroteWhen inverting a matrix, I get a different output between (1) evaluating the inverse of a matrix and (2) defining a new variable as the inverse of the original matrix and evaluating the new variable
Set your matrix inversion to NUMERIC ...yellow in there.
Page3 MatrixForum.sm (99 KiB) downloaded 60 time(s).
WroteWroteWhen inverting a matrix, I get a different output between (1) evaluating the inverse of a matrix and (2) defining a new variable as the inverse of the original matrix and evaluating the new variable
Set your matrix inversion to NUMERIC ...yellow in there.
Page3 MatrixForum.sm (99 KiB) downloaded 60 time(s).
That worked perfectly. Thank you! Is there an Explain It Like I'm 5 as to why we need to specify the numeric solver rather than symbolic to get the right answer?
WroteThat worked perfectly. Thank you! Is there an Explain It Like I'm 5 as to why we need to specify the numeric solver rather than symbolic to get the right answer?
By default, everything you define in Smath is symbolic.
Matrix inverse are numeric from libraries [mostly Cholesky]
Thus, specify inverse as numeric to comply with Smath plugins.
Will you sleep better ! Jean.
-
New Posts
-
No New Posts