Asked by Taner Dubie
on 10 Nov 2018 at 23:48

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

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

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

Taner Dubie
on 11 Nov 2018 at 1:49

Matt J
on 11 Nov 2018 at 1:51

Well, why not solve symbolically anyway and then convert the result to double?

Taner Dubie
about 22 hours ago

I tried to convert to double but I couldn't get it to work.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429159-how-to-solve-ax-b-matrix-when-i-know-some-x-s-and-some-b-s#comment_635487

## Taner Dubie (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/429159-how-to-solve-ax-b-matrix-when-i-know-some-x-s-and-some-b-s#comment_635491

Sign in to comment.