Problem of Symbolic function evaluation

syms u [2 1]
f(u) = u'*u;
f(1,2) % Correct syntax the ans is 5
f([1;2]) %Incorrect syntax Symbolic function expected 2 input arguments but received 1.
Why can the input of a function only be two variables, not a vector? What if there are many variables, such as 100 variables? It is too troublesome to input 100 values one by one during evaluation.

 採用された回答

Torsten
Torsten 2022 年 10 月 13 日

0 投票

u = sym('u',[2 1]);
f = u.'*u
f = 
result = subs(f,u,[1;2])
result = 
5

1 件のコメント

Morty
Morty 2022 年 10 月 13 日
Thank you very much for your answer! I have been confused about this problem for some days.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

リリース

R2022b

タグ

質問済み:

2022 年 10 月 13 日

コメント済み:

2022 年 10 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by