I am trying to represent a non linear system in simulink. I'm using embedded matlab function. I have defined a vector dx in terms of combinations of states and inputs, and plan to use ode15s to solve thisfunction dx = f(L,x)
%define dx as a vector
dx=zeros(4,1);
dx(1)=x(3);
dx(2)=x(4);
dx(3)=x(1)-2*x(4)-0.9*(x(1)+0.1)/-0.1*(x(1)-0.9);
dx(4)=x(2)-2*x(3)-0.9*x(2)/-0.1*x(2);
Then type:
[L,x]=ode15s('platefincondenser',ht,x0)
(%x0 and ht is defined.)
in the command window, then it appears to work.
My problem has been in implementing this in simulink. I even addded the integrator block, but where should I mention about the ode15s in simulink, with 4 intial conditions and 4 outputs.
error:
Attempted to access local or constant data 'ode15s' (#140). This is not supported. Please remove this data from the model explorer.
Function 'Embedded MATLAB Function' (#124.484.523), line 24, column 1:
"[L,x]= ode15s('platefincondenser',L,x0)"
Launch diagnostic report.
Any kind of help is appreciated.
Thank you in advance for your time and consideration.
cheers
VJ
My code is:
function serratedfins
%#eml
global Qexp Two
Pt=599240; %N/m^2
y=0;
QT=0.0; %W/m
%fl=0.00000001; %kg/s
Qexp=975900; %W
ifgnh3=1236*10^3; %J/kg
fg=Qexp/ifgnh3; % kg/s
fl=0.001; %kg/s
Two=280.17; % K
maxL = 2.344; %m
x0 = [Pt y QT fl fg Two];
L = [0 maxL];
%options=odeset('initialslope',2.4,'maxstep',1);
%options=odeset('initialslope',2.4,'maxstep',0.004);
eml.extrinsic('ode15s');
[L,x]= ode15s('platefincondenser',L,x0);
function dx=platefincondenser(L,x,x0)
global Qexp Two
% iam using fzero too for calculations of parameters with Qexp , Two etc.
dx=zeros(4,1);
dx(1)=x(3);
dx(2)=x(4);
dx(3)=x(1)-2*x(4)-0.9*(x(1)+0.1)/-0.1*(x(1)-0.9);
dx(4)=x(2)-2*x(3)-0.9*x(2)/-0.1*x(2);
Thank you.
Cheers
Vinz
"Vinz A" <vin...@gmail.com> wrote in message
news:hrfk6v$reg$1...@fred.mathworks.com...
Thank you for your response for Embedded Matlab functions.
As you said, I tried writing everthing as a single function, but still I am getting an error.
Could you please guide me for the below simple example,
function dx = newcheckfcn
%#eml
eml.extrinsic('newcheckfcn','ode15s');
a=5;
b=25;
L = [0 2];
dx= ode15s('newcheckfcn',L,a,b);
dx = zeros(2,1);
dx(1)=a+b;
dx(2)=a/b;
Cheers
vinz
Can anyone please help me with the embedded matlab functions.
Is there any particular way to define ode15s in Simulink.
Below is a simple example, that I will be using
function [x,y] = inputsnum
%#eml
eml.extrinsic('ode15s');
a=5;
b=25;
L = [0 2];
[x,y]= ode15s('newcheckfcn',L,a,b);
function [x,y] = newcheckfcn(L,a,b)
x=a+b;
y=a/b;
Thank you
Vinz
%----------------------------------------
function p = foo(level,a,b,mu,sigma)
y = quad(@(x)mypdf(x,mu,sigma),a,b);
p = y > level;
function y = mypdf(x,mu,sigma)
x = x - mu;
t = -(x.*x)./(2*sigma*sigma);
y = exp(t)./(sqrt(2*pi)*sigma);
%----------------------------------------
Now, because QUAD isn't supported by Embedded MATLAB and requires either a
function name or handle or some such, you simply cannot compile this
function for Embedded MATLAB. Declaring QUAD extrinsic doesn't work because
you can't pass a function or a function name to an extrinsic function.
Instead, create your own extrinsic function
%----------------------------------------
function y = mycdf(a,b,mu,sigma)
y = quad(@(x)mypdf(x,mu,sigma),a,b);
function y = mypdf(x,mu,sigma)
x = x - mu;
t = -(x.*x)./(2*sigma*sigma);
y = exp(t)./(sqrt(2*pi)*sigma);
%----------------------------------------
and put it on the MATLAB path. Notice there is NO %#eml for this file. Do
not try to compile it. Do not pass its name on the command line to emlc or
emlmex. Instead, just write your Embedded MATLAB driver
function p = foo(level,a,b,mu,sigma) %#eml
eml.extrinsic('mycdf');
y = 0;
y = mycdf(a,b,mu,sigma);
p = y > level;
Now *this* function can be compiled. It doesn't matter how much *data* you
need to pass to MATLAB in order for MYCDF to do its work. What's important
here is that MYCDF is extrinsic (not compiled), and we do not need to pass
function handles or names from Embedded MATLAB to MATLAB.
I just used QUAD as an example of a function that takes a function handle as
input. I should note for completeness here that Embedded MATLAB supports
QUADGK already. Unfortunately, Embedded MATLAB does not support any ODE
integrators right now.
--
Mike
"Vinz A" <vin...@gmail.com> wrote in message
news:hrn0cs$n51$1...@fred.mathworks.com...
Thank you very much for the detailed explaination.
I tried solving a simple example and it worked.
I have one more question, how to define the size of the variable.
For example:
If I have only one differential equation I will mention as
x=zeros(1,1);
but it is asking to reframe the size of the variable to
x=zeros(11,1);
I am working with steady state, not varying with time, in that case how can I obtain the value of the last value after the differentation is done.
Hope I am clear.
Thank you for your time and consideration.
Regards
Vinz
Thank you very much for the detailed explaination.
I tried solving a simple example and it worked.
I have one more question, how to define the size of the variable.
For example:
If I have only one differential equation I will mention as
x=zeros(1,1);
but it is asking to reframe the size of the variable to
x=zeros(11,1);
I am working with steady state, not varying with time, in that case how can I obtain the value of the last value after the differentation is done.
Hope I am clear.
Thank you for your time and consideration.
Regards
Vinz