フィルターのクリア

How do I convert multivariate function handle to symbolic function? Anyone has any ideas?

9 ビュー (過去 30 日間)
Shawn Miller
Shawn Miller 2016 年 2 月 1 日
コメント済み: Walter Roberson 2016 年 2 月 2 日
My function handle is as follows,
g=@(p)p(1)+p(2)
I can compute using function handle using something like
g([1,2])
Now I want to convert it to a symbolic function, but seems MATLAB has trouble assuming p(1) and p(2) as symbol. So
syms p(1)
sym(g)
doesn't work. I guess I might need to change p(1),p(2) to p1,p2, but this is hard, too. Anyone can help?

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 2 月 1 日
P = sym('p', [1 2]);
G = g(P);
now G will be a symbolic expression in p1, p2. You can then convert it to a symbolic function by using
Gsym = feval(symengine, 'fp::unapply', G, P(1), P(2));
  4 件のコメント
Shawn Miller
Shawn Miller 2016 年 2 月 2 日
Seems G=symfun(G,symvar(G)) also works.
Walter Roberson
Walter Roberson 2016 年 2 月 2 日
Ah, that sounds good.

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by