MATLAB Answers

0

How to solve Ax=b matrix when I know some x's and some b's

Asked by Taner Dubie on 10 Nov 2018 at 23:48
Latest activity Commented on by Taner Dubie about 22 hours ago
So I have a problem where I know all of the 'A' matrix and 3 out of the 8 in the 'b' matrix and 5 out of the 8 from the 'x' matrix. I know how to separate it and do it by hand, but I am not sure how to solve this in Matlab. The code below is what I have so far.
r1=[0.24,1.2e3,0.24,1.2e3,0,0,0,0];
r2=[1.2e3,8e6,1.2e3,8e6,0,0,0,0];
r3=[-0.24,-1.2e3,0.4533,400,-.2133,-1.6e3,0,0];
r4=[1200,4e6,400,24e6,1600,8e6,0,0];
r5=[0,0,-0.2133,-1600,0.6933,-8e6,-.48,-2400];
r6=[0,0,1600,8e6,-8000,32e6,2400,8e6];
r7=[0,0,0,0,-.48,-2400,.48,-2400];
r8=[0,0,0,0,2400,8e6,-2400,16e6];
%Matrices
A=[r1;r2;r3;r4;r5;r6;r7;r8];
syms Ra Ma Rb Mb Rc Mc Rd Md Va Ta Vb Tb Vc Tc Vd Td
b=[Ra,Ma,-5,0,Rc,50,Rd,Md]';
x=[0,0,Vb,Tb,0,Tc,0,0]';

  2 Comments

You seem to be missing an r1 value.
Yes I just noticed that as well. I just fixed it, thank you for noticing.

Sign in to comment.

2 Answers

Answer by Matt J
on 11 Nov 2018 at 2:00
Edited by Matt J
on 11 Nov 2018 at 2:13
 Accepted Answer

For a fully numerical solution, just bring the matrix columns corresponding to unknowns over to the left hand side of the equation and all columns corresponding to the knowns over to the right hand side:
X=[0,0,nan,nan,0,nan,0,0].';
B=[nan,nan,-5,0,nan,50,nan,nan].';
I=eye(8);
xi=isnan(X);
bi=isnan(B); %logical maps
lhs=[A(:,xi), -I(:,bi)];
rhs=I(:,~bi)*B(~bi) - A(:,~xi)*X(~xi);
solution = lhs\rhs

  1 Comment

Thank you I think this worked.

Sign in to comment.


Answer by Matt J
on 11 Nov 2018 at 1:29
Edited by Matt J
on 11 Nov 2018 at 1:42

Since you're solving symbolically, you don't have to re-arrange the equations. Just use
solve( sym(A)*x==b, [Ra,Ma,Rc,Rd,Md,Vb,Tb,Tc])

  3 Comments

I don't want to solve symbolically actually, I just put the symbols in there to fill the matrix. I actually wanted the answers for all of the symbolic variables I made.
Well, why not solve symbolically anyway and then convert the result to double?
I tried to convert to double but I couldn't get it to work.

Sign in to comment.