Can we distinguish between variables and parameters in a symbolic function?
4 ビュー (過去 30 日間)
古いコメントを表示
Mohammad Shojaei Arani
2022 年 12 月 15 日
コメント済み: Mohammad Shojaei Arani
2022 年 12 月 17 日
Hello,
I have a simple (perhaps naive, if so my appology) question. Consider the following
syms x f(x) x
f(x) = a*x;
Is there a way to distinguish between 'x' and 'a'? If I use symvar(f) it just gives the information about all vars and aparetly
cannot distinguish between x and a.
Any idea?
Thanks in advance,
Babak
2 件のコメント
Dyuman Joshi
2022 年 12 月 15 日
symvar determines symbolic variables in the expression. Since you have not defined a as a symbolic variable in the above code, symvar won't classify a as an output.
What is the data type of a?
採用された回答
Dyuman Joshi
2022 年 12 月 15 日
syms f(x) a m n z
f(x)=a*x
y=symvar(f)
I understand what you mean by 'cannot distinguish between x and a'
But, this is how syms variable are expressed in arrays. For example -
z=[m n]
However, you can convert the symbolic expression to string and obtain seperate variables -
z=symvar(char(f))
6 件のコメント
その他の回答 (1 件)
Walter Roberson
2022 年 12 月 17 日
f_variables = argnames(f)
f_param = setdiff(symvar(f), f_variables)
This is not the same thing as "all variables mentioned that are not parameters". symvar does not report any "bound" variables or any variables being used as functions.
A bound variable is like x in
int(f(x), x, a, b)
provided that f does not itself contain x then you could substitute any other variable name without affecting the output, like
int(f(Dummy), Dummy, a, b)
int() and symsum() and symprod() can all use bound variables.
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!