Borrar filtros
Borrar filtros

How to use symbolic expression with matlab coder

1 visualización (últimos 30 días)
Drew Mitchell
Drew Mitchell el 30 de Mzo. de 2016
Comentada: Walter Roberson el 30 de Mzo. de 2016
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??

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Mzo. de 2016
Editada: Walter Roberson el 30 de Mzo. de 2016
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 comentarios
Drew Mitchell
Drew Mitchell el 30 de Mzo. de 2016
Any idea how to do that?
Walter Roberson
Walter Roberson el 30 de Mzo. de 2016
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.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by