Extracting the base name and size of symbolic variables

4 次查看(过去 30 天)
Hello,
I have a simple question. Consider the following:
syms a [3 3] real
syms x r [3 1] real
mu(x) = (r.*x).*(1-a*x)
Now, I would like to know the symbolic variables and their sizes in the symbolic function mu(x). If I use symvar(mu) I can only get the
variables in a scalar form and this command does not help to get the size of matrixes and vectors. You might think that it should not be
a big deal to write a code for this. However, ingeneral this is not possible. Foe instance, consider the following example:
syms x beta0 w w0 w1 w2
mu(x) = x+beta0+w+w0+w1+w2
In this example there is not a unique interpretation of the variables in terms of matrices, vectors, and scalars. One interpretation is to consider w = [w1 w2] as a vector. But, another interpretation is to consider al w's as scalar (which is the correct interpretation).
Why I need this?
I am performing a parameter estimation procedure to estimate the parameters of a function like mu(x). When I want to represent the results I do not like to display them scalar-wiae. rather I prefer to display the outcomes based on their actual sizes.
I hope MATLAB has a command to handled this issue?
Thanks,
Babank

回答(1 个)

Walter Roberson
Walter Roberson 2024-9-20
syms a [3 3] real
That is equivalent to
a = sym('a', [3 3], 'real')
mu(x) = (r.*x).*(1-a*x)
When scanning that code, the value of a is substituted, as-if you had written
mu(x) = (r.*x).*(1-sym('a', [3 3], 'real')*x)
The code does not remember that the value came from the variable a
So what you want to do is not possible.
  4 个评论
Walter Roberson
Walter Roberson 2024-9-20
The substitution of the value for the variable is inherent in how symbolic mathematics works. There is no chance that you would be able to recover variable a from mu(x) = (r.*x).*(1-a*x);
Mohammad Shojaei Arani
You are right.
My point was about displaying the results in an elegant way which corresponds with the way the function is defined.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by