Definite integral in (embedded) Matlab function, with passing additional parameters to the integrand
1 view (last 30 days)
I have a simulation file to model the dynamic behaviour of system, at each time step , I need to evaluate a time-independent integral. To do so I use (embedded) Matlab function but I got many errors. Any help would be appreciated.
inside my (embedded) Matlab function is:
%%________________ method one
Notes: 1-my integrand is actually very complicated but I put something simple here.
2-I have been told to use "quadgk" instead of "inregra;", but it did not worked
3- I also tried the following method but it did not helped!
%%________________ method two
Mike Hosea on 18 Dec 2014
Edited: Mike Hosea on 18 Dec 2014
If you don't need to generate code for your model, I think you can use your second approach, but you need to fix a few unrelated errors. Put myFunc into a MATLAB file myFunc.m. There is a syntax error. Remove the comma between @(theta) and y1:
Now let's consider your block code. I didn't know whether you meant for your variable to be called "positions" or "position". I just picked one. Second, to call an extrinsic function, you have to pre-allocate the output to tell the compiler how to interpret the mxArray that comes back from MATLAB. The block code should look something like this:
% Define the output type for myFunc, in this case a scalar double.
% Evaluate myFunc in MATLAB.
If you do need to generate code, the way I tell people to do this is to use persistent variables to store the parameters of the function. The whole thing could go into the block.
function v = integrand(theta,y1set,y2set)
persistent y1 y2
y1 = 0;
y2 = 0;
% More than one input means we are setting the persistent
% parameter values, not evaluating the integrand function
% on this particular call. The theta argument is ignored.
% We make it a string 'set positions' in the calling code
% solely for readability.
if nargin > 1
y1 = y1set;
y2 = y2set;
% nargout had better be zero, since we haven't set v.
v = y1 + y2*theta;