Handling Symbolic Matrices in R as in Matlab
<p>I am failing to appropriately work with a Symbolic Matrix in R, with both rSymPy and Ryacas. In Matlab this is easy. <strong>I am looking for suggestions how to do this in R and get a similar output as in Matlab</strong>. To do this in Matlab I need the 'Symbolic Toolbox'.</p>

<p>In this example I wish to generate a Symbolic transition probability matrix "P", which is say 5 x 5, and has elements P11, P12,..., P55. I then want to use this matrix for multiplication (with itself and other matrices) and potentially perform also other operations.</p>

<p><strong>(1) Matlab - Generate Symbolic Matrix -> OK</strong></p>

<pre><code>P = sym('P%d%d', [5 5])
</code></pre>

<p><strong>(1) R - Get Symbolic Matrix -> OK</strong></p>

<pre><code>library(rSymPy)
P&lt;-matrix(nrow=5, ncol=5)
for (i in 1:5){
  for (j in 1:5) {
P[i,j]&lt;-paste0(Sym("P"), i, j) # tried Var("P") also
  }
}
</code></pre>

<p>then I want to mulitply these matrices. </p>

<p><strong>(2) Matlab - Multiply Symbolic Matrix  -> OK</strong></p>

<pre><code>P*P 
</code></pre>

<p>works just fine.</p>

<p><strong>(2) R - Multiply Symbolic Matrix -> Problem</strong></p>

<pre><code>sympy("P * P")
Need Help Here!
</code></pre>

<p>does not work. Many other attempts did not work either. I need suggestions on how to do this correctly and get the same output as, for example, in (2) Matlab.</p>

<p>Additional Task:</p>

<p><strong>(3) Matlab - sym() each element separately -> OK</strong></p>

<p>Moreover I would ask for a suggestion how to Sym() a single element of the matrix P in R as in Matlab. </p>

<pre><code>for i = 1:5;
    for j = 1:5;
    P = sprintf('P%d%d',i,j); 
    assignin('caller',P,sym(P));
    end;
end;
</code></pre>

<p><strong>(3) R - Sym() each element separately -> Problem</strong></p>

<pre><code>Need Help Here!
</code></pre>

<p>Thx for all suggestions!</p>