posts - 81, comments - 262, trackbacks - 0

Generating a Symbolic Vector in Matlab


Matlab's symbolic toolbox is great for abstracting algebraic operations. For example, generating Lagrange basis functions. However, when generalizing an operation of order n, n symbolic variables are needed. Creating n symbolic variables in Matlab isn't as obvious as creating a static set of symbols. For example:

 

syms x y

 

vs.

 

syms x1 x2 x3 xn

 

Fortunately the function sym takes a string argument and returns the symbolic variable. This way we can build a string for each xi, and append the resulting variable into a container such as a vector. Generating n symbolic variables can be done like so

 

% generate xi symbolic values

xi = [];

for (i=1:n)

t = sym(['x' int2str(i)]);

xi = [xi; t];

end

 

 

We now have a symbolic vector with n variables


Print | posted on Friday, October 1, 2010 7:59 PM |

Powered by:
Powered By Subtext Powered By ASP.NET