MATLAB Answers

Solving Matrices with Symbolic Variables

335 views (last 30 days)
Jared
Jared on 30 Nov 2011
Commented: JITHA K R on 4 Jan 2018
I am trying to figure out how to solve a problem such as [A]{X}={0} where [A] is a numerical matrix such as
[1 2 3 4]
[5 6 7 8]
[9 0 1 2]
and {X} is a symbolic matrix with a single numeric value such as
[1x1 sym; 1x1 sym; 1x1 sym; 1]
that is:
[a]
[b]
[c]
[1]
Is there a way to find a,b,c such that [A]{X}={0}

  0 Comments

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 30 Nov 2011
A =[ 1 2 3 4
5 6 7 8
9 0 1 2]
syms a b c
x = [a;b;c]
k = A(:,1:3)\-A(:,end);
for i1 = 1 : numel(x)
eval([char(x(i1)),'=k(i1)']);
end

  3 Comments

Jared
Jared on 30 Nov 2011
thanks alot works well, one minor adjustment:
k = cell2mat(A(:,1:3))\-cell2mat(A(:,end));
Karan Gill
Karan Gill on 1 Dec 2016
It's much simpler. See Kaixiang Wang's answer below.
JITHA K R
JITHA K R on 4 Jan 2018
Can you explain the working of this code pls?

Sign in to comment.

More Answers (2)

Kaixiang Wang
Kaixiang Wang on 30 Nov 2016
Edited: Kaixiang Wang on 30 Nov 2016
Simply use MATLAB symbolic toolbox and the solve() function.
syms a b c
A=[1 2 3 4;5 6 7 8;9 0 1 2]
X=[a;b;c;1]
sol=solve(A*X)

  0 Comments

Sign in to comment.


Walter Roberson
Walter Roberson on 30 Nov 2011
Edited: John Kelly on 27 May 2014
Linear algebra with symbolic matrices is discussed at http://www.mathworks.com/products/symbolic/

  0 Comments

Sign in to comment.

Sign in to answer this question.