필터 지우기
필터 지우기

Definite integral in (embedded) Matlab function

조회 수: 2 (최근 30일)
sahand
sahand 2012년 11월 11일
Hi
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
Q=quad(@myfun,lo,up);
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

답변 (4개)

Fred Smith
Fred Smith 2012년 11월 12일
In later versions the MATLAB Function block supports QUAD directly, so if you can upgrade that is your best option.

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 11일
If you don't need to run in real time, instead of embedded function, use Matlab function.
  댓글 수: 2
sahand
sahand 2012년 11월 11일
But it's going to be a part of real time simulation
Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 11일
편집: Azzi Abdelmalek 2012년 11월 11일
You have to make your own code (trapezoidal rule for example) http://en.wikipedia.org/wiki/Trapezoidal_rule very easy to do

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2012년 11월 11일
If possible, integrate symbolically first and use the closed form formula, instead of trying to integrate in your embedded code.
  댓글 수: 2
sahand
sahand 2012년 11월 11일
I wish,but if it is not, Is there any other way?
Walter Roberson
Walter Roberson 2012년 11월 11일
What constraints can you give as to what the function to be integrated will look like? It is not practical to numerically integrate arbitrary functions with arbitrary accuracy in any real-time digital system, but if the functions are sufficiently "well-behaved" it might be practical.

댓글을 달려면 로그인하십시오.


Mike Hosea
Mike Hosea 2013년 3월 1일
Use QUADGK, not QUAD.

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by