Definite integral in (embedded) Matlab function
10 views (last 30 days)
I am trying to implement an evolutionary optimization algorithm in the middle of a simulink model via (embedded) matlab function. There is a need for computing a definite integral in the algorithm. Therefore in the first step and just for understanding the issue, the following definite integral was coded in (embedded) matalb editor:
function Q = DefinitIntegral(up,lo)
%#up & lo are inputs of the block as upper and lower limits of integration
function y = myfun(x)
y = x.^2+2*x+1;
But an error occurred:
The function 'quad' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation.
How could it be fixed
Best regards, Sahand Radmanesh
Fred Smith on 12 Nov 2012
In later versions the MATLAB Function block supports QUAD directly, so if you can upgrade that is your best option.
Azzi Abdelmalek on 11 Nov 2012
If you don't need to run in real time, instead of embedded function, use Matlab function.
Walter Roberson on 11 Nov 2012
If possible, integrate symbolically first and use the closed form formula, instead of trying to integrate in your embedded code.