How I can get coefficients matrix from the set of linear equations?

9 views (last 30 days)
Hello,
I am having problem in extraction of coefficients out of my set of symbolic linear equations. Equations are as such
R =
[0.8978*c - 0.8047*b - 0.020299*a, 0.8978*d - 0.094800*b - 0.106799*a]
[ 0.091199*a + 0.13200*c - 0.8047*d, 0.091199*b - 0.106799*c + 0.0575*d]
How I can get the coefficient matrix, that is my result will look like
R_coeff =
-0.0203 -0.8047 0.8978 0
-0.1068 -0.0948 0 0.8978
0.0912 0 0.1320 -0.8047
0 0.0912 -0.1068 0.0575
Thanks

Answers (1)

Walter Roberson
Walter Roberson on 25 Jan 2013
You might be able to vectorize this over R; I do not have the toolbox to test with.
All_Vars = symvar(R);
R_Trans = R.';
for J = 1 : numel(R_Trans)
This_R = R_Trans(J);
for K = 1 : length(All_Vars)
Coeff_For_This_var = coeffs(This_R, This_Var(K));
R_coeff(J, K) = Coeff_For_This_var(2); %var^1
end
end
The transpose is in order to get R(1,2)'s coefficients to appear before R(2,1)

Community Treasure Hunt

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

Start Hunting!