How to expand a symbolic matrix expression?
Mostra commenti meno recenti
I want to expand all terms in a complex symbolic matrix expression by the distributive law of the expression.
tempa1 = symmatrix('A1',[2 2]);
tempb1 = symmatrix('B1',[2 2]);
tempc1 = symmatrix('C1',[2 2]);
tempd1 = symmatrix('D1',[2 2]);
for nn = 2:5
tempa2 = symmatrix(sprintf('A%d',nn),[2 2]);
tempb2 = symmatrix(sprintf('B%d',nn),[2 2]);
tempc2 = symmatrix(sprintf('C%d',nn),[2 2]);
tempd2 = symmatrix(sprintf('D%d',nn),[2 2]);
tempa = tempa1*tempb2+tempc1*tempd2+tempb1*tempa2+tempd1;
tempb = tempa2*tempb1+tempc2*tempd1+tempb2*tempa1+tempd2;
tempc = tempa1*tempb1+tempc1*tempd1+tempb1*tempa1+tempd2;
tempd = tempa2*tempb2+tempc2*tempd2+tempb2*tempa2+tempd1;
tempa1 = tempa;
tempb1 = tempb;
tempc1 = tempc;
tempd1 = tempd;
end
vec_1 = symmatrix('vec_1',[2 1]);
result = tempa*vec_1;
When the variable result is executed, it is output as a complex matrix expression.
The variable result is a 2 by 2 symbolic matrix, and each element is also returned as a symbolic expression.
However, the information I need is not an element expression, but a string of expressions output when the variable result is executed.
When the variable result is executed, looking at the output result, the variable vec_1 is expressed by multiplying the result of tempa outside the bracket.
I want all the brackets to be solved and each term to be multiplied by vec_1.
A bulti-in function called 'expand' is identified as the most similar function to what I want.
However, this function is not supported for symmatrix input.
To use this function, if you run symmatrix2sym on the variable result, it returns all element representations.
Please, let me know that.
Thank you.
3 Commenti
Dyuman Joshi
il 3 Ago 2023
If it not necessary to use symmatrix, you can define 2x2 symbolic variables instead.
Lee Jong Hyun
il 4 Ago 2023
Hi Lee Jong Hyun,
I could be wrong, but I don't think you'll be able to easily get the result you're looking for.
But suppose you could, i.e., get an expression for tempa in the form (n = 2)
syms A1 A2 B1 B2 C1 D1 D2 [2 2] matrix
syms vec_1 [2 1] matrix
tempa = A1*B2*vec_1 + B1*A2*vec_1 + C1*D2*vec_1 + D1*vec_1
What whould be the next step in the process? Maybe there's a way to achieve the goal without forming tempa as shown?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


