Thread Subject: s-function, parameter

Subject: s-function, parameter

From: sdfs sfdf

Date: 27 Oct, 2009 11:24:03

Message: 1 of 3

Hello,

i have an s-function to which the parameter "L" is handed over. The beginning of the s-function looks like this :
Code:
function [sys,x0,str,ts] = Kinetik_aerob(t,x,u,flag,V_l,c_X_0,A,L)
 
switch flag,
   
  case 0,
     [sys,x0,str,ts]=mdlInitializeSizes(V_l,c_X_0,A,L);
     
  case 3,
     sys=mdlOutputs(t,x,u,V_l,c_X_0,A,L);
   
  case {1, 2, 4, 9},% unexpected flags
     
  otherwise
    error(['Unhandled flag = ',num2str(flag)]);
 
end
%
function [sys,x0,str,ts]=mdlInitializeSizes(V_l,c_X_0,A,L)
 
sizes = simsizes;
 
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 7;
sizes.NumInputs = 6;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
 
sys = simsizes(sizes);
%
x0 = [];
str = [];
ts = [0 0];
%


function sys=mdlOutputs(t,x,u,V_l,c_X_0,A,L)
 
%Einlesen
c_X = u(1); %[g/l] Biomassekonzentration
PFD = u(2); %[?E/m?s] PFD(PAR)
E = u(3); %[MJ]
Ab = u(4); %[g/l]
Temp = u(5); %[?K]
Gh = u(6); %[W/m^2]



%Now the part with which i have problems. The if-else-construction:
if L==1
PFD = PFD*( (-0.9184 * c_X) / (0.1447 + c_X) + 1.002 );

elseif L==3
PFD = PFD* ( (-0.9714 * c_X) / (0.04037 + c_X) + 1 );


It seems as if the s-function cannot handle this if-construction or the if-construction doesn't recognize the parameter "L". If i calculate "PFD" without the if-construction it works. What is wrong? Please help me ;-)

Thank you
bye

Subject: s-function, parameter

From: sdfs sfdf

Date: 27 Oct, 2009 15:04:04

Message: 2 of 3

Sorry, i forgot the "end" after the if-else-construction. But this is not the problem. It doesn't work anyway

"sdfs sfdf" <ofeus18@yahoo.de> wrote in message <hc6l8j$4k0$1@fred.mathworks.com>...
> Hello,
>
> i have an s-function to which the parameter "L" is handed over. The beginning of the s-function looks like this :
> Code:
> function [sys,x0,str,ts] = Kinetik_aerob(t,x,u,flag,V_l,c_X_0,A,L)
>
> switch flag,
>
> case 0,
> [sys,x0,str,ts]=mdlInitializeSizes(V_l,c_X_0,A,L);
>
> case 3,
> sys=mdlOutputs(t,x,u,V_l,c_X_0,A,L);
>
> case {1, 2, 4, 9},% unexpected flags
>
> otherwise
> error(['Unhandled flag = ',num2str(flag)]);
>
> end
> %
> function [sys,x0,str,ts]=mdlInitializeSizes(V_l,c_X_0,A,L)
>
> sizes = simsizes;
>
> sizes.NumContStates = 0;
> sizes.NumDiscStates = 0;
> sizes.NumOutputs = 7;
> sizes.NumInputs = 6;
> sizes.DirFeedthrough = 1;
> sizes.NumSampleTimes = 1;
>
> sys = simsizes(sizes);
> %
> x0 = [];
> str = [];
> ts = [0 0];
> %
>
>
> function sys=mdlOutputs(t,x,u,V_l,c_X_0,A,L)
>
> %Einlesen
> c_X = u(1); %[g/l] Biomassekonzentration
> PFD = u(2); %[?E/m?s] PFD(PAR)
> E = u(3); %[MJ]
> Ab = u(4); %[g/l]
> Temp = u(5); %[?K]
> Gh = u(6); %[W/m^2]
>
>
>
> %Now the part with which i have problems. The if-else-construction:
> if L==1
> PFD = PFD*( (-0.9184 * c_X) / (0.1447 + c_X) + 1.002 );
>
> elseif L==3
> PFD = PFD* ( (-0.9714 * c_X) / (0.04037 + c_X) + 1 );
>
>
> It seems as if the s-function cannot handle this if-construction or the if-construction doesn't recognize the parameter "L". If i calculate "PFD" without the if-construction it works. What is wrong? Please help me ;-)
>
> Thank you
> bye

Subject: s-function, parameter

From: Phil Goddard

Date: 27 Oct, 2009 20:12:22

Message: 3 of 3


You need to be more precise in describing what you mean by
> It seems as if the s-function cannot handle this if-construction or the if-construction doesn't recognize the parameter "L". If i calculate "PFD" without the if-construction it works. What is wrong? Please help me ;-)

Is it erroring out?
If so what is the error message?

Or are you not calculating PFD even if you are _seemingly_ inputting L=1 or L=3?
In which case you should look at Section 6.1 of the FAQ:
http://matlabwiki.mathworks.com/MATLAB_FAQ

Or is it something else?

Phil.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
sfunction Phil Goddard 27 Oct, 2009 16:14:05
simulink Phil Goddard 27 Oct, 2009 16:14:05
parameter sdfs sfdf 27 Oct, 2009 07:29:05
ifconstruction sdfs sfdf 27 Oct, 2009 07:29:05
sfunction sdfs sfdf 27 Oct, 2009 07:29:04
rssFeed for this Thread

Contact us at files@mathworks.com