WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Problem mit sfunction

 

Papillon
Forum-Anfänger

Forum-Anfänger


Beiträge: 18
Anmeldedatum: 04.06.09
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 28.06.2009, 18:25     Titel: Problem mit sfunction
  Antworten mit Zitat      
Hallo!

Ich beschäftige mich gerade zum ersten Mal mit einer sfunction, und stoße dabei leider auf ein Problem. Ich habe einen Simulink Block "Level-2 S-Function" mit einem Eingang und zwei Ausgängen. In ihm wird auf die sfunction verwiesen, außerdem werden zwei Parameter (die Anfangsbedingungen) übergeben: 0.856,0.886.

Die sfunction sieht so aus:

Code:

function cstr_sfunction(block)
% CSTR   -  Mixed logical dynamical system (MLD):
%           Level-2 M file S-Function of cstr
%           solving mixed-integer inequality system by MILP


setup(block);
 
%endfunction

function setup(block)
 
  block.NumDialogPrms  = 2;
 
  %% Register number of input and output ports
  block.NumInputPorts  = 1; % Eingang u
  block.NumOutputPorts = 2; % Ausgänge x und y

  %% Setup functional port properties to dynamically
  %% inherited.
  block.SetPreCompInpPortInfoToDynamic;
  block.SetPreCompOutPortInfoToDynamic;

  % Dimensionen der Eingangsports
  block.InputPort(1).Dimensions        = 1;
  block.InputPort(1).SamplingMode = 'Sample';
  block.InputPort(1).DirectFeedthrough = false;
 
  % Dimensionen der Ausgangsports  
  block.OutputPort(1).Dimensions       = 2;
  block.OutputPort(1).SamplingMode = 'Sample';
  block.OutputPort(2).Dimensions       = 1;
  block.OutputPort(2).SamplingMode = 'Sample';
 
  %% Set block sample time
  block.SampleTimes = [1 0];
 
  %% Register methods
  block.RegBlockMethod('PostPropagationSetup',    @DoPostPropSetup);
  block.RegBlockMethod('InitializeConditions',    @InitConditions);  
  block.RegBlockMethod('Outputs',                 @Output);  
  block.RegBlockMethod('Update',                  @Update);  
 
%endfunction

function DoPostPropSetup(block)

  %% Setup Dwork
  block.NumDworks = 1;
 
  block.Dwork(1).Name = 'x';
  block.Dwork(1).Dimensions      = 2;   % x ist zweidimensional
  block.Dwork(1).DatatypeID      = 0;
  block.Dwork(1).Complexity      = 'Real';
  block.Dwork(1).UsedAsDiscState = true;
 
%   block.Dwork(2).Name = 'x2';                       % zweiter Zustand ?
%   block.Dwork(2).Dimensions      = 1;
%   block.Dwork(2).DatatypeID      = 0;
%   block.Dwork(2).Complexity      = 'Real';
%   block.Dwork(2).UsedAsDiscState = true;

%endfunction

function InitConditions(block)

  %% Initialize Dwork
  x10 = block.DialogPrm(1).Data;    % AB werden von den Parametern des Blockes übernommen
  x20 = block.DialogPrm(2).Data;
 
  block.Dwork(1).Data = [x10;x20];

  cstr_init;

%endfunction

function Output(block)

  block.OutputPort(1).Data = cstr_update(block.Dwork(1).Data, block.InputPort(1).Data); % x
  block.OutputPort(2).Data = cstr_output(block.Dwork(1).Data, block.InputPort(1).Data); % y
 
%endfunction

function Update(block)

  block.Dwork(1).Data = cstr_update(block.Dwork(1).Data, block.InputPort(1).Data);    % x
 
%endfunction

function cstr_init()
  global A B1 B2 B3 C D1 D2 D3
  global A11 A22 A33 B11 B22 B33 b11 b22 b33

  % Model Eqn. (6)
A11 = [0.8889 -0.0123; 0.1254 0.9751];
A22 = [0.8241 -0.0340; 0.6365 1.1460];
A33 = [0.6002 -0.0463; 2.4016 1.2430];

B11 = [-0.0002; 0.0296];
B22 = [-0.0005; 0.0322];
B33 = [-0.0007; 0.0338];

b11 = [0.1060; -0.0852];
b22 = [0.1907; -0.7537];
b33 = [0.3119; -1.7083];

C = [1 0];

% Initial Conditions

xs1 = [0.856; 0.886];
xs2 = [0.5528; 2.7517];
xs3 = [0.2353; 4.7050];

xs = xs2;

%   MLD Konstanten
m1 = -0.0143;
m2 = -1.7759;
M1 = 1.0158;
M2 = 8.2189;

m = [m1; m2];
M = [M1; M2];

e = 1e-9;



A = [0 0; 0 0];
B1 = [0; 0];
B2 = [0 0 0 0; 0 0 0 0];
B3 = [1 0 1 0 1 0; 0 1 0 1 0 1];

E2 = zeros(40,1);
E2(1:4,1:2) = [0.65 0; -0.35-e 0; 0 0.22; 0 -0.78-e];
E2(11:16,1:4) = [1 0 1 0; 0 1 1 0; -1 -1 -1 0; 1 0 0 1; 0 -1 0 1; -1 1 0 -1];
E2(17:24,3) = [-M1 -M2 m1 m2 -m1 -m2 M1 M2]';
E2(25:32,4) = [-M1 -M2 m1 m2 -m1 -m2 M1 M2]';
E2(33:40,1) = [-M1 -M2 m1 m2 -m1 -m2 M1 M2]';

E3 = zeros(40,6);
E3(17:24,1:2) = [1 0; 0 1; -1 0; 0 -1; 1 0; 0 1; -1 0; 0 -1];
E3(25:32,3:4) = [1 0; 0 1; -1 0; 0 -1; 1 0; 0 1; -1 0; 0 -1];
E3(33:40,5:6) = [1 0; 0 1; -1 0; 0 -1; 1 0; 0 1; -1 0; 0 -1];

E1 = zeros(40,1);
E1(9:10,:) = [1; -1];
E1(17:40) = [0 0 0 0 B11' -B11' 0 0 0 0 B22' -B22' 0 0 0 0 B33' -B33']';

E4 = zeros(40,2);
E4(1:10,:) = [-1 0; 1 0; -1 0; 1 0; 1 0; -1 0; 0 1; 0 -1; 0 0; 0 0];
E4(21:24,:) = [A11; -A11];
E4(29:32,:) = [A22; -A22];
E4(37:40,:) = [A33; -A33];

E5 = zeros(40,1);
E5 = [1 -0.35-e 1 -0.78-e 0 1 0 6 2 2 1 1 -1 1 0 0 0 0 0 0 b11'-m' -b11'+M' 0 0 0 0 b22'-m' -b22'+M' 0 0 0 0 b33'-m' -b33'+M']';
 
  % MILP initialization
  mld_sim(E1, E2, E3, E4, E5);

%endfunction

function y = cstr_output(x, u)
  global C D1 D2 D3 d z
  [d, z] = mld_sim(x, u);
  y = C*x;

%endfunction

function xp1 = cstr_update(x, u)
  global A B1 B2 B3 d z
  xp1 = A*x+B1*u+B2*d+B3*z;
 
%endfunction
 


Wenn ich nun im Simulink-File die Simulation starte, bekomme ich folgende Fehlermeldung:

Zitat:

Error evaluating registered method 'Outputs' of M-S-Function 'cstr_sfunction' in 'cstr_mld/Level-2 M-file S-Function'. Error using ==> mtimes
Inner matrix dimensions must agree. The following is the MATLAB call stack (file names and line numbers) that produced this error:
['C:...\cstr_sfunction.m'] [174]
['C:...\cstr_sfunction.m'] [79].


Nun finde ich aber nicht den Fehler. Irgendetwas stimmt wohl nicht in den Dimensionen in cstr_update, aber ich sehe nicht was es ist.

Kann mir einer weiterhelfen? Danke schonmal!

Papillon
Private Nachricht senden Benutzer-Profile anzeigen


Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.