Take a look at
syms x y z
A=[1 -2 x;2 1 y;-3 1 z]
rref(A)
This is an augmented matrix and I need the final output to be
1 0 | (x 2y)/5
0 1 | (y-2x)/5
0 0 | z x y
But rref()
yeilds this
1 0 0
0 1 0
0 0 1
Any suggestions how to get the intended output?
CodePudding user response:
As long as the symbolic variables are confined to the right half of your augmented matrix, you could proceed as follows. Suppose that [A|B] is your augmented matrix. Then, you could do the following.
M = rref([A, eye(size(A,1))]);
C = M(:,(size(A,2) 1):end) * B;
In this case, C is the result of applying the row operations that brought M to its RREF to the symbolic matrix B.
Here's a modification that produces the result you initially expected.
syms x y z
A=[1 -2;2 1;-3 1];
B=[x;y;z];
[m,n] = size(A);
M = [eye(m),zeros(m,n)];
M(:,1:n) = A;
M(:,(m 1):end) = eye(m,n);
P = M(:,n 1:end);
R = rref(M);
C = R(:,n 1:end)/P*B;
disp(C)
Result:
x/5 (2*y)/5
y/5 - (2*x)/5
x y z