Pulling coefficients out of symbolic matrix to solve

2 views (last 30 days)
I am having some issues making a model I've constructed useful for every case. I have two 2x2 matrices of constants. Currently I have MATLAB construct symbolic expressions for each point with expressions such as: 78(A11) + 33(A21) + 66(A33) + 89(B22) etc.
I take the coefficients out using coeffs and sym2poly and form a matrix, Q, and using Q\b where b is my collection of target values for each expression, I'm able to solve for the A and B matrices of constants. This is great.
My problem is, I have no idea what order my constants are in without checking them by hand. If an expression has just an a21 value, I need to pad it out to 0 a21 0 0 in the matrix so my regression will work correctly. But since each expression is a 1x1 symbolic variable I can't use any line search techniques I know of. I really need to be able to trust my code to pull out the coefficients and assemble them in my matrix in the correct order, putting zeros in the right places rather than changing the code every time I use new data.
I appreciate your help on this matter. Thanks!

Answers (0)

Community Treasure Hunt

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

Start Hunting!