# Splitting a matrix into addition of two same size Matrices

1 view (last 30 days)
Sidharth Agarwal on 28 Jul 2020
Answered: Walter Roberson on 30 Jul 2020
A 12*12 Matrix P is given to us,this matrix has each of it's element as a quadratic expression in symolic variable x3.This Matrix P needs to be made into an addition of 3 different 12*12 matrices A,B,C such that P=A*x3^2+B*x3+C
How can we find these matrices A,B,C in matlab ?

KSSV on 28 Jul 2020
Edited: KSSV on 28 Jul 2020
x3 = rand(12) ;
A = rand ;
B = rand ;
C = rand ;
P = A*x3.^2+B*x3+C ;
If A, B, C are matrices
x3 = rand(12) ;
A = rand(12) ;
B = rand(12) ;
C = rand(12) ;
P = A.*x3.^2+B.*x3+C ;

Sidharth Agarwal on 29 Jul 2020
The matrix P is already defined and needs to be split with x3 as a single symbolic variable.
KSSV on 29 Jul 2020
Okay..you mean you have P, A, B, C matrices..and you want x3.?
Sidharth Agarwal on 30 Jul 2020
It is mentioned in the orginal question that I have a 12*12 P matrix which has each of it's element as a quadratic expression in symbolic variable x3.This Matrix P needs to be made into an addition of 3 different 12*12 matrices A,B,C such that P=A*x3^2+B*x3+C
How can we find these matrices A,B,C in matlab ?

Walter Roberson on 30 Jul 2020
parts_cell = arrayfun(@(s) coeffs(s,x3,'all'), P, 'uniform', 0);
parts_matrices = num2cell(vertcat(parts_cell{:}),1);
A = reshape(parts_matrices{1}, size(P));
B = reshape(parts_matrices{2}, size(P));
C = reshape(parts_matrices{3}, size(P));

R2017a

### Community Treasure Hunt

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

Start Hunting!