Extracting the base name and size of symbolic variables
6 ビュー (過去 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
0 件のコメント
回答 (1 件)
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
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);
参考
カテゴリ
Help Center および File Exchange で Special Values についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!