필터 지우기
필터 지우기

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