Apply a matrix to a function

2 ビュー (過去 30 日間)
Johnny Yoon
Johnny Yoon 2021 年 1 月 7 日
コメント済み: Johnny Yoon 2021 年 1 月 25 日
Dear Matlab experts,
I would like to apply a matrix into a function as follows.
clear all;
sizee = 1000;
syms 'T' [1 sizee]
T_syms = sym('T', [1 sizee]);
f = sym(zeros(sizee, sizee));
f(:,:) = T1 + T2 + T3 + T4 + ... + T1000; % This is just to make sample equations.
x_vars = (1:1000);
f_ftn (T_syms) = f;
solution = f_ftn(x_vars);
However, I got an error "Symbolic function expected 1000 input arguments but received 1." So, it seems I can't apply a matrix directly to a function. Is there any way that a matrix can be applied to a function? I can use matlabFunction as follows. However, it takes a way too long, like hours. Is there any way which takes a shorter amount of time? Thank you.
f_ftn02 = matlabFunction(f, 'Vars', {T_syms});
solution = f_ftn02(x_vars);
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 1 月 22 日
f_ftn02 = matlabFunction(f, 'Vars', {T_syms});
is the way. You could experiment, though, with
f_ftn02 = matlabFunction(f, 'Vars', {T_syms}, 'optimize', false);
As you are not writing to a file, I do not expect it to make any difference, but I saw a recent hint somewhere that some optimization is maybe now being done even when not writing to files, so you could try
Johnny Yoon
Johnny Yoon 2021 年 1 月 25 日
Thank you again for your answer. It worked!

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

採用された回答

Deepak Meena
Deepak Meena 2021 年 1 月 22 日
編集済み: Deepak Meena 2021 年 1 月 22 日
Hi Johnny,
As far as my understanding goes , it is not possible. Because when you create a symbolic function indexed with a list of syms , the MATLAB will consider it as single entity.
But you can do something like this
clear all;
sizee = 1000;
syms 'T' [1 sizee]
T_syms = sym('T', [1 sizee]);
f = sym(zeros(sizee, sizee));
f(:,:) = T1 + T2 + T3 + T4 + ... + T1000; //or use sum(T_syms)
x_vars = (1:1000);
H(T_syms) = f;
cells = num2cell(x_vars);
H(cells{:});
  1 件のコメント
Johnny Yoon
Johnny Yoon 2021 年 1 月 25 日
Thank you very much for your answer. It works!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by