Help solving system of equations with initial value

I am trying to simulate a system of springs according to the example given here: http://en.wikipedia.org/wiki/Spring_system. In terms of the example I'm following, after some math, you have three equations and three unknowns. You replace one of the unknowns with an initial value (step 6?). What would be a good way to solve for the other two unknowns (x2 and x3) using Matlab? If it were just 3 eqs./three unk., I could do it by multiplying by the inverse etc. I can work it out on paper, but it needs to be expandable to hundreds of eqs, and to multiple dimensions so I require a relatively straight forward method. Currently, I am using matrices to represent the system but I suppose I could revert to equations and use symbolic math? I feel like this should be easy but I'm coming up dry. Enormous thanks to anyone that might be able to help.
Thanks, Jeremy

 Réponse acceptée

Matt Fig
Matt Fig le 14 Août 2012
Modifié(e) : Matt Fig le 15 Août 2012
You start out with:
A = [1 -1 0;-1 2 -1;0 -1 1];
b = [-1 -1 2].'
But you know x(1) = 2;
x = [2;nan;nan];
So we need to eliminate each row and column where we have a known in A, and each row in b.
An = A([2 3],[2 3]); % Leave out first row and column.
% Multiply eliminated col in A by the known and subtract.
bn = b([2 3])-2*A([2 3],1);
Now to find x:
x(2:3) = [An\bn]

3 commentaires

Jeremy
Jeremy le 15 Août 2012
Thanks Matt! Works like a charm.
Matt Fig
Matt Fig le 15 Août 2012
Thanks for the interesting question!
What's really interesting is, that it actually doesn't matter which rows you choose to eliminate!
A = [1 -1 0;-1 2 -1;0 -1 1];
b = [-1 -1 2].'
Amod = A(:,[2 3]);
bmod = b - 2*A(:,1);
% All are the same
Amod\bmod
Amod([1 2],:)\bmod(1:2)
Amod([1 3],:)\bmod([1 3])
Amod([2 3],:)\bmod(2:3)

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by