This project has moved. For the latest updates, please go here.

System of Linear Equations

Oct 9, 2012 at 5:53 PM
Edited Oct 11, 2012 at 6:38 AM

Hey, thanks for reading,

I have a system of linear equations as follows

[vector]= [matrix] [vector]

(edit - this system is not correct, the correct system is [vector]= [matrix] [vector] + [vector] ) please see the picture linked below.

However, there is a mix of knowns and unknowns in both of the vectors.

This is part of a larger method, so the system will always be well behaved.  There will always be as many unknowns as there are equations, and each linear equation will only have a single unknown. However, I have no knowledge before hand if that unknown will be on the left side or the right side of the equal sign.

Any advice for how to solve for the unknowns?  I have looked through the sample code but this problem seems to never be addressed.

Coordinator
Oct 9, 2012 at 7:34 PM

If each linear equation only has a single unknown, you can symbolically solve all equations independently. So this is not exactly an equation system, just N independent equations.

Then, all finite linear equation systems can be transformed into standard form Ax=y, where A and y are known and x is unknown (at which point you can use our algorithms to solve it).

Maybe I'm missing something. Can you give an example?

Oct 11, 2012 at 6:36 AM

Hey again.

Thanks for your help.  I thought I had come up with a solution and I was going to report back once I had implemented it, but it turns out that my solution wasn't one.

Anyway, I am trying to solve the equation shown in this picture:

https://dl.dropbox.com/u/217910/IMAG0081.jpg

I have the matrix "K" and the vector "Ff", but I don't know to solve for the four unknowns.

There doesn't seem to be any code in the samples showing how to deal with this situation.

Thanks again for the help.

Oct 11, 2012 at 7:39 AM
Edited Oct 11, 2012 at 7:39 AM

So here's what I think I should do:

pull out degrees of freedom 2 and 4 to get this equation

{0,0} = {{.4,.2},{.2,.4}}{d2,d4) + {20.16,-30.24}

Which is easy enough to solve with LU Decomposition

Then take the resulting d2 and d4 and plug them back into the equation, solving for F1 and F3

Is that the best approach?

Coordinator
Oct 12, 2012 at 7:51 AM
Edited Oct 12, 2012 at 7:51 AM

Exactly, except there's no need to solve for F1 and F3 then, as they can then be directly evaluated:

F# code sample:

open MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.FSharp

let d = (matrix [[0.4;0.2];[0.2;0.4]]).LU().Solve(vector [-20.16;30.24])
let F = (matrix [[0.06;0.06];[-0.06;-0.06]]) * d + vector [7.39;13.6]
printfn "d2=%A d4=%A F1=%A F3=%A" d.[0] d.[1] F.[0] F.[1]

Which returns d2=-117.6 d4=134.4 F1=8.398 F3=12.592 on my system

Coordinator
Oct 12, 2012 at 8:02 AM
Edited Oct 12, 2012 at 11:22 AM

Btw, alternatively you could bring it into normal form as I mentioned above and solve it in one go:

// Ax=b
let A = matrix [[-1.0;0.0;0.06;0.06];[0.0;0.0;0.4;0.2];[0.0;-1.0;-0.06;-0.06];[0.0;0.0;0.2;0.4]]
let b = vector [-7.39;-20.16;-13.6;30.24]
let x = A.LU().Solve(b)
printfn "d2=%A d4=%A F1=%A F3=%A" x.[2] x.[3] x.[0] x.[1]

Which returns exactly the same solution as above. As you can see, I moved F1 and F3 to the right side (i.e. substracted it from both sides) as the first two columns, with coefficients 0 or -1.