how to implement symbolic matlab function on simulink?

im trying to implement the following function on matlab function on simulink but error 'syms is not supported for a stand alone code generation' occures
function fkt = fcn(c,p,k,N)
syms t
ft=p^(-c/2)*(c/2)*t.^((c/2)-1).*exp(-(t./p).^(c/2));
Ft=1-exp(-(t/p).^(c/2));
fkt=k*nchoosek(N/2,k)*(1-Ft)^(N/2-k)*(Ft)^(k-1)*ft
end

2 件のコメント

Nicolas Schmit
Nicolas Schmit 2017 年 10 月 18 日
Simulink works only with numerical data. Why do you need to use the Symbolic Toolbox in a MATLAB function?
Fatma Abdullah
Fatma Abdullah 2017 年 10 月 18 日
um working on paper to try to simulate complicated system with calculations of integration and convolution that are almost impossible to be evaluated in matlab.....um taking the easy way instead of complicated matlab programing

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

回答 (1 件)

Sean de Wolski
Sean de Wolski 2017 年 11 月 2 日

0 投票

You can do this by putting syms inside of a function called by a MATLAB Function block where the inner function is flagged as extrinsic:

5 件のコメント

Walter Roberson
Walter Roberson 2017 年 11 月 2 日
Hmmm -- though that would still not help if you were doing code generation.
Sean de Wolski
Sean de Wolski 2017 年 11 月 2 日
編集済み: Sean de Wolski 2017 年 11 月 2 日
Nope, was that one of the requirements?
There is the matlabFunction tool that will rewrite symbolic expressions for MATLAB (and equivalent for Simulink)
Walter Roberson
Walter Roberson 2017 年 11 月 2 日
"'syms is not supported for a stand alone code generation'"
The user has not clarified if they are just trying to run in Acceleration mode or if they are trying to generate code for standalone work.
The table of relative speeds suggests using Fcn blocks instead of MATLAB Function blocks as being faster. Unfortunately nchoosek() is not supported by Fcn blocks; I discussed above how to use Fcn blocks for all except that part.
It is not clear from the table of relative speeds whether the slow part is in the execution or in some kind of startup cost, so it is not clear to us whether moving everything practical to a Fcn block and doing as little as possible in the MATLAB Function block is a good strategy or if instead "if you are going to use a MATLAB Function block at all, might as well toss everything into it as you only pay the overhead cost once" is the case ?
Fatma Abdullah
Fatma Abdullah 2017 年 11 月 2 日
i'm trying to generate code for standalone work, not in acceleration mode
Walter Roberson
Walter Roberson 2017 年 11 月 2 日
In that case, extrinsic is not going to work, unfortunately. You will need to use a MATLAB Function block for at least the nchoosek; perhaps it would be easier to put it all into a MATLAB Function block to do the
(c*k*t^(c/2 - 1)*exp(-(t/p)^(c/2))^(N/2 - k + 1)*nchoosek(N/2, k)*(1 - exp(-(t/p)^(c/2)))^(k - 1))/(2*p^(c/2))

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

カテゴリ

ヘルプ センター および File ExchangeSimulink Coder についてさらに検索

質問済み:

2017 年 10 月 17 日

コメント済み:

2017 年 11 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by