Reputation: 692
I want to solve the integral of expm(A*s)
between a
and b+tau
, where tau
is time-varying delay.
I created in Simulink a Matlab Function block with tau
as an input, like this:
function y = compute_int(u, tau)
syms s
gamma=double(int(expm(A*s),s,a,b+tau));
B = [gamma; 1]
y = B*u;
with A
, a
and b
being defined before. There is a problem though: the function syms
is not supported by simulink.
Any ideas to how to handle the integral? I tried with
coder.extrinsic('syms');
but it doesn't work.
thanks for any suggestions!!
Upvotes: 4
Views: 3508
Reputation: 11228
The most useful way:
We can't use Symbolic variables and anonymous function in Simulink. But we can create another .m file for out function and load it into Matlab Function Block in Simulink:
myIntegral.m
function out = myIntegral(in)
A = [1 2 3; 4 5 6; 7 8 9];
myfun = @(s) expm(A.*s);
out = integral(myfun,0,in,'ArrayValued',true);
end
Matlab Function block code:
function y = fcn(u)
%#codegen
coder.extrinsic('myIntegral');
y = zeros(3);
y = myIntegral(u);
P.S. By the way - I tried
syms s1
and there is no error here, but Simulink still can't use this s1
variable:
Undefined function or variable 's1'.
Upvotes: 2