How to use symbolic expression with matlab coder

1 回表示 (過去 30 日間)
Drew Mitchell
Drew Mitchell 2016 年 3 月 30 日
コメント済み: Walter Roberson 2016 年 3 月 30 日
I have a symbolic expression that I would like to integrate using a mex file. I know how to do the integration the following way:
function f=test_fun(x)
f=x.^2;
end
^This is the function I am integrating
function q=test_int(a,b)
q=quadgk(@test_fun,a,b);
end
^This is the call to integrate that function:
Using this I can successfully create a mex file.
My problem is that in my test_fun file, I would like to use a symbolic expression that I have loaded with load('') for f rather than explicitly typing the equation because it is way to long to type. I would like to do something like this if possible.
function f=test_fun(x)
load('f') %f is a symbolic expression of x
f=eval(f);
end
Is there a way to do this??

採用された回答

Walter Roberson
Walter Roberson 2016 年 3 月 30 日
編集済み: Walter Roberson 2016 年 3 月 30 日
No. The Symbolic Toolbox cannot be used with MATLAB Compiler or MATLAB Coder at all.
You might be able to load a function handle; I am not certain about that.
If not, then you would need to read the expression and convert it into a data structure that your code then evaluated somehow (without using eval() or str2func())
  2 件のコメント
Drew Mitchell
Drew Mitchell 2016 年 3 月 30 日
Any idea how to do that?
Walter Roberson
Walter Roberson 2016 年 3 月 30 日
I do not have the Compiler to test loading function handles saved non-encrypted.
Building data structures to execute code is a large topic. The difficulty depends upon the permitted forms of the code that is to be understood. For example, building something to handle Reverse Polish Notation is relatively simple, but needing to be able to match brackets is surprisingly complex.
You would find it much easier to restrict the forms of the equations that can be entered, and have the user enter the coefficients. For example you could give the user an option menu for selecting polynomials of order 1, 2, or 3, with floating point coefficients that the user entered.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by