Change viewing format (Console) for the result of an operation made with symbolic variables

Hi.
I'm having problems to manage large results when I make symbolic operations and I view them in Matlab console (understanding problems , because of the massive existence of parentheses in the visualization in console)
Well, I have this output of my symbolic operation (if it's important, I employ pretty( simple(Variable_Result) ) previously to obtain anything in matlab console). In this code , "simple" gives me the best simplification for the symbolic expression, while "pretty" gives me the best console format for that simplified expression output.
Text copy-pasted from console when I use the code above:
L11 am_ix - (s_iz + d_i cos(ai)) (wd_antz sin(ai) + cos(ai) cos(q_i) (wd_anty - qd_i w_antx) - cos(ai) sin(q_i) (wd_antx + qd_i w_anty)) + L12 am_iy + L13 am_iz +
(s_iy + d_i sin(ai)) (wd_antz cos(ai) - cos(q_i) sin(ai) (wd_anty - qd_i w_antx) + sin(ai) sin(q_i) (wd_antx + qd_i w_anty)) +
((s_ix + y_i) (sin(ai) (qd_i + w_antz) + w_anty cos(ai) cos(q_i) - w_antx cos(ai) sin(q_i)) - (s_iy + d_i sin(ai)) (w_antx cos(q_i) + w_anty sin(q_i)))
(sin(ai) (qd_i + w_antz) + w_anty cos(ai) cos(q_i) - w_antx cos(ai) sin(q_i)) - ((s_iz + d_i cos(ai)) (w_antx cos(q_i) + w_anty sin(q_i)) -
(s_ix + y_i) (cos(ai) (qd_i + w_antz) - w_anty cos(q_i) sin(ai) + w_antx sin(ai) sin(q_i))) (cos(ai) (qd_i + w_antz) - w_anty cos(q_i) sin(ai) + w_antx sin(ai) sin(q_i)) - vd_antx cos(q_i) -
vd_anty sin(q_i)
As you can see, it's a hard and slow work, specially if you have "N" expressions like these.. Also I need to create a document later copy-pasting these lines, a I want to make it as fast as possible.
To sum up: if someone knows how to obtain an output in console (result of a symbolic operation) that uses a jerarchic relationship of "markers" (ie. "{,[,(") ) in order not to confuse the user, I would be very pleased.
Thanks in advance.
I wait for your response.
Oscar.

Answers (2)

There is no built-in Matlab routine to do what you are asking.
If I recall correctly, the result from pretty() should be a plain character string rather than something symbolic. You have an unpleasant text-processing task ahead.
Changing the brackets wouldn't be so bad if you were to use a particular bracket as the outermost level, with the brackets cycling through an order as you got deeper and deeper. But that's not usually the way such things are formatted: usually, the deepest brackets are set to a particular bracket type and the bracket types cycle through as you get less deep. That requires that you figure out what your deepest nesting is first before you can assign any symbols. Usually the easiest way to do that is recursion, or recursion curryed to be iterative.
You could also approach the problem from the symbolic level, writing your own pretty() routine. Maybe it could be done in a single MuPad expression, but it would be a lot clearer written as a set of MuPad procedures. How familiar are you with writing your own MuPad procedures?
I could probably work out appropriate Maple code, but some of the Maple operators I would want to use do not translate directly in to MuPad. In particular, I don't have experience translating the way MuPad handles data type testing, and as it is now getting late on a Friday night, I find that I am not presently eager to work it out from the documentation (I don't have MuPad myself.)
Maybe I could change the strategy to solve the problem... I will explain to you.
I need to operate with that expression (the one I've pasted as code) in order to obtain its variance. The expression is a function f such that: expresion = f(x1, x2, constants)
and my purpose is to obtain VAR(expresion)=VAR( f(x1, x2, constants) ). Note I don't need to know what's the variance of each one of the variables: I only need to know which one of the symbolic variables are going to be taken into account by Matlab to compute a expression of the variance (more details in the following link).
http://en.wikipedia.org/wiki/Variance > Properties, formal
The input could be that expression (without formatting with "pretty") and the "uncorrelated variable" names; and the output, another expression that takes into account the following elemental relationships between 2 variables (assume, for simplicity, that the x1, x2... xn are uncorrelated).
Example: INPUT1: '4*x*y+2*x*z*y*m+32+32*m' (expression through which calculate the variance) INPUT2: 'x,y,z' (list of statistical variables, assume uncorrelated for simplicity).
The output could be (arbitrarious order of each one of the addings): '16*VAR[x]*VAR[y]+(2*m)^2*VAR[x]*VAR[y]*VAR[Z]'
(details about the variance formula when using statistical variables uncorrelated on the link above, note that the particular case of constant times variable pertains to the general case referenced on the link and named "Weighted sum of variables").
This would be another angle of view of the problem, that allows me to paste the expression in my script... I think this solution is the best, but I don't know how can I create my own symbolic variance function (I assume that this function would be completely MuPAD based)
If someone can help a bit, I will be very pleased.
Thanks in advance.
Oscar

Products

Asked:

on 5 Mar 2011

Community Treasure Hunt

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

Start Hunting!