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

### Taner Dubie (view profile)

on 10 Nov 2018
Latest activity Commented on by Taner Dubie

on 11 Nov 2018

### Matt J (view profile)

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]';

Walter Roberson

### Walter Roberson (view profile)

on 11 Nov 2018
You seem to be missing an r1 value.
Taner Dubie

### Taner Dubie (view profile)

on 11 Nov 2018
Yes I just noticed that as well. I just fixed it, thank you for noticing.

on 11 Nov 2018
Edited by Matt J

### Matt J (view profile)

on 11 Nov 2018

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

Taner Dubie

### Taner Dubie (view profile)

on 11 Nov 2018
Thank you I think this worked.

on 11 Nov 2018
Edited by Matt J

### Matt J (view profile)

on 11 Nov 2018

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])

Taner Dubie

### Taner Dubie (view profile)

on 11 Nov 2018
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.
Matt J

### Matt J (view profile)

on 11 Nov 2018
Well, why not solve symbolically anyway and then convert the result to double?
Taner Dubie

### Taner Dubie (view profile)

on 11 Nov 2018
I tried to convert to double but I couldn't get it to work.