From: Hasan Al-Rubaye on
Hi there,

In Simulink, I'm trying to differentiate a function with respect to a non-time variable. So I created an embedded matlab function and wrote down the following:

function phi = func(B)
syms x;
phi = diff(cosh(B*x)-cos(B*x)...),x);

This function works if called from Matlab console, but with Simulink it complains that "command duality is not supported". What's the way to do it then?

Thanks,
Hasan
From: Steven Lord on

"Hasan Al-Rubaye" <hasan.rubaie(a)hotmail.com> wrote in message
news:hu17ji$he4$1(a)fred.mathworks.com...
> Hi there,
>
> In Simulink, I'm trying to differentiate a function with respect to a
> non-time variable. So I created an embedded matlab function and wrote down
> the following:
>
> function phi = func(B)
> syms x;
> phi = diff(cosh(B*x)-cos(B*x)...),x);
>
> This function works if called from Matlab console, but with Simulink it
> complains that "command duality is not supported". What's the way to do it
> then?

I don't know if Embedded MATLAB supports the use of MATLAB objects inside an
Embedded MATLAB function; even if it does, I'm almost certain that the
output argument of the Embedded MATLAB function cannot be a MATLAB object
(like a sym object, as would be the case for your function.)

To avoid the error that you received, you could replace:

syms x;

with:

x = sym('x');

but you will likely also need to convert phi into a double array using SUBS
or DOUBLE (substituting a numeric value for x) before you return it from
func.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Michael Hosea on
Embedded MATLAB is mainly a code generation tool and supports only a
*subset* of MATLAB. Command duality is just the "command" syntax

syms x;

instead of the functional syntax

syms('x');

But fixing that won't help because Embedded MATLAB does not support SYMS
either way.

Fortunately, Embedded MATLAB does allow pass-through execution in MATLAB
through the use of "extrinsic" functions. What you need to do is write a
MATLAB function that takes B and any abscissas you want to evaluate your
function at. Then declare that function extrinsic, declare it's output size
and type, and then call it. Your Embedded MATLAB block will then look
something like

function y = f(B,x) %#eml
eml.extrinsic('myfunc');
y = zeros(size(x));
y = myfunc(B,x);

where MYFUNC does *not* have %#eml in it, is not compiled. AFAIK, it is
necessary to encapsulate all your symbolic work in a MATLAB function
*outside* Embedded MATLAB.
--
Mike

"Hasan Al-Rubaye" <hasan.rubaie(a)hotmail.com> wrote in message
news:hu17ji$he4$1(a)fred.mathworks.com...
> Hi there,
>
> In Simulink, I'm trying to differentiate a function with respect to a
> non-time variable. So I created an embedded matlab function and wrote down
> the following:
>
> function phi = func(B)
> syms x;
> phi = diff(cosh(B*x)-cos(B*x)...),x);
>
> This function works if called from Matlab console, but with Simulink it
> complains that "command duality is not supported". What's the way to do it
> then?
>
> Thanks,
> Hasan


From: Walter Roberson on
Michael Hosea wrote:
> Embedded MATLAB is mainly a code generation tool and supports only a
> *subset* of MATLAB. Command duality is just the "command" syntax
>
> syms x;
>
> instead of the functional syntax
>
> syms('x');
>
> But fixing that won't help because Embedded MATLAB does not support SYMS
> either way.
>
> Fortunately, Embedded MATLAB does allow pass-through execution in MATLAB
> through the use of "extrinsic" functions.

Note, though, that if the intent happens to be to compile, then you will need
to avoid symbolic processing, as Matlab does not support compiling the
symbolic toolbox.