4

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!!

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
Betelgeuse
  • 682
  • 2
  • 8
  • 27

1 Answers1

2

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);

It works: enter image description here

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'.

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
  • I have just found that an other way to compute the integral could be the block "interpreted matlab fnc" – Betelgeuse Feb 16 '17 at 15:18
  • And also there are [continuous integral](https://www.mathworks.com/help/simulink/slref/integrator.html) and [discrete integral](https://www.mathworks.com/help/simulink/slref/discretetimeintegrator.html) blocks. They can be useful too! – Mikhail_Sam Feb 17 '17 at 06:37