Solving Ax=B where B is symbolic and x unknown?

How do I solve Ax=B when B is symbolic and x unknown?
For example, in the trivial case:
1*x+0*y=a
0*x+1*y=b
I'd like MATLAB to output x=a and y=b. (Obviously I have more complex matrices...)
I'm new to MATLAB and skimmed through the symbolic toolbox but couldn't really find what I need (or maybe found and didn't understand).
Help, please? Thanks.
p.s. How do I indicate a 'new line' in this post box? (Instead of pressing 'enter' twice)

 Accepted Answer

eg:
A = rand(8);
b = sym('b',[8,1]);
x = vpa(A\b,5);
ADD on Walter's comment:
for jj = 1:8
b(jj) = sym(sprintf('b%-d',jj));
end

3 Comments

Note: the syntax sym('b',[8,1]) is relatively new (R2011a I think it was.)
I typed in:
A=[3 0; 0 2];
b=[sym('p'); sym('q')]
b/A
and got:
[p/3, 0]
[q/3, 0]
Instead of something meaning x=p/3 and y=q/2.
Using vpa is not helpful, gives decimal notation instead of fractions.
Never mind, A\b works - thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!