フィルターのクリア

Convert a symbolic equation to a vector equation

8 ビュー (過去 30 日間)
Daniel Wells
Daniel Wells 2011 年 9 月 8 日
コメント済み: Walter Roberson 2018 年 11 月 7 日
I would like to be able to input a multi-variate symbolic equation into MATLAB and convert that equation into a function which takes in a vector. I know that matlabFunction() can turn this symbolic function into a function handle, but that equation does not take in a vector, but rather a list of inputs. -Is there a command which will convert my symbolic expression to a vector equation? -If not, is there a way to convert the function handle returned by matlabFunction() to one that takes in a vector?

採用された回答

Walter Roberson
Walter Roberson 2011 年 9 月 8 日
Start with
S = vectorize(char(EXPRESSION))
To turn that in to an anonymous function depends upon your MATLAB version. If you have a very new version, you can use
f = str2func(['@(x) ' S]);
The (x) should be whatever list of symbolic names is in your symbolic expression.
If you do not have one of the very newest versions, then you:
eval(['f = @(x) ' S]);
Yes, ugly and evil, but we have to play the hand we are dealt.
  2 件のコメント
Daniel Shub
Daniel Shub 2011 年 11 月 28 日
I think f = eval(['@(x) ' S]); might be a bit safer and easier to deal with since you are not poofing a variable into the workspace.
Walter Roberson
Walter Roberson 2018 年 11 月 7 日
Good point, Daniel.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by