MATLAB Answers


Solving for two uknown vectors in a matrix equation

Asked by Björn Aurell Hansson on 2 Apr 2019
Latest activity Answered by Torsten
on 2 Apr 2019
So I have a matrix A (which is given) and its nullspace is 5x3 and its row space is 5x2,
so the basis of the nullspace and the basis of the row space will form a basis for R^5 and I want to calculate the values for two vectors such that these two basises form a vector that I have.
I.e I want to solve
Where N is the vectors that form a base for my nullspace and R is the vectors that form a base for my rowspace, and are my uknowns and
so to calculate this in matlab I tried the following:
A = [...] %too lazy to type it out as it's quite big
N = null(sym(A)); %5x2 matrix
R = colspace(sym(A')); %5x3 matrix
x = [1 2 3 4 5]';
syms t s %my unknowns
[t, s] = solve(N*t+R*s == x, t, s)
but whatever I do, I either get that my array sizes doesn't match. Which doesn't make sense to me because the dimensions of t should be 2x1 and the dimensions of s should be 3x1, or it tells me something about that my vectors aren't symbolic which makes even less sense.
I don't specify the dimensions anywhere for t and s which I guess could be a problem, but I didn't find a way of doing this unless I also filled them with elements which is not what I want to do.
Anyways, I'd really appreciate any help I can get.
Thanks in advance!


Sign in to comment.




1 Answer

Answer by Torsten
on 2 Apr 2019

syms t1 t2 s1 s2 s3
[solt1 solt2 sols1 sols2 sols3] = solve([N*[t1;t2]+R*[s1;s2;s3] == x],[t1 t2 s1 s2 s3])


Sign in to comment.