The following is a simple example that illustrated the use of TomSym:

>> toms y
>> toms 3x1 x
>> toms 2x3 A
>> f = (A*x).^(2*y)

f = tomSym(2x1):


>> derivative(f,A)

ans = tomSym(2x6):


In the above example, the 2x1 symbol f is differentiated with respect to the 2x3 symbol A. The result is a 2x6 matrix, representing d(vec(f))/d(vec(A)).

The displayed text is not necessarily identical to the m-code that will be generated from an expression. For example, the identity matrix is generated using speye in m-code, but displayed as eye (Derivatives tend to involve many sparse matrices, which Matlab handles efficiently). The mcodestr command converts a tomSym object to a matlab code string.