Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Problem in hybrid model simulation of recursive least squares.

Problem in hybrid model simulation of recursive least squares.

Hi!
I am a new user of modelica. I am trying to run a hybrid simulation of recursive least square (discrete) and a sine wave (continuous). In a nutshell, i sample the sine wave and try to do the least square estimation of the curve of sine wave (meaning fitting the curve with a line). just like moving average filter, i perform estimation using three sample values; forgetting(ignoring) previous ones and recieving the new ones.

so when i run the code i get the following error.

a->dim_size[0] != b->dim_size[0], 1 != 2
Assertion failed: base_array_shape_eq(source, dest), file real_array.c, line 177

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


my code is


block RLS
  annotation(Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Rectangle(visible=true, fillColor={255,255,255}, extent={{-100.0,-100.0},{100.0,100.0}}),Text(visible=true, origin={-7.8354,3.7854}, fillPattern=FillPattern.Solid, extent={{-67.8354,-33.7854},{67.8354,33.7854}}, textString="RLS", fontName="Arial")}), Diagram(coordinateSystem(extent={{-148.5,-105.0},{148.5,105.0}}, preserveAspectRatio=true, initialScale=0.1, grid={5,5})));
  Modelica.Blocks.Interfaces.RealInput errorsample annotation(Placement(visible=true, transformation(origin={-95.0,36.9418}, extent={{-20.0,-20.0},{20.0,20.0}}, rotation=0), iconTransformation(origin={-120.0,0.0}, extent={{-20.0,-20.0},{20.0,20.0}}, rotation=0)));
  Modelica.Blocks.Interfaces.RealOutput predictedcontrol annotation(Placement(visible=true, transformation(origin={60.0,35.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=0), iconTransformation(origin={110.0,-0.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=0)));
  import Modelica.Math.Matrices.*;
 
  Real A[3,2];
  Real b[3,1];
  Real gammalyp[2,1];
  Real ATA[2,2];
  Real ATb[2,1];
 
  Real errorsample0,errorsample1,errorsample2,errorsample3;
  Real predictedcontrol1,predictedcontrol2,predictedcontrol3;
 
  parameter Real gamma=1;   parameter Real lyp=1;
 
  Boolean fastsample;   Integer i(start=0);

equation
  fastsample=sample(0, .01);

algorithm
  when fastsample then
      i:=i + 1;
  end when;

algorithm
  if noEvent(i == 1) then
    errorsample0:=errorsample;
    predictedcontrol1:=errorsample0/gamma - sqrt(2*lyp)/gamma;
    predictedcontrol:=predictedcontrol1;
  elseif noEvent(i == 2) then
    errorsample1:=errorsample;
    predictedcontrol2:=errorsample1/gamma - sqrt(2*lyp)/gamma;
    predictedcontrol:=predictedcontrol2;

  elseif noEvent(i == 3) then
    errorsample2:=errorsample;
    predictedcontrol3:=errorsample2/gamma - sqrt(2*lyp)/gamma;
    predictedcontrol:=predictedcontrol3;
  else
    errorsample3:=errorsample;
    A:={{predictedcontrol1,1},{predictedcontrol2,1},{predictedcontrol3,1}};
    b:={{errorsample1},{errorsample2},{errorsample3}};
    ATA:=transpose(A)*A;
    ATb:=transpose(A)*b;
    gammalyp:=solve(ATA, ATb);
    predictedcontrol:=errorsample3/gammalyp[1,1] - gammalyp[2,1]/gammalyp[1,1];
    predictedcontrol1:=predictedcontrol2;
    predictedcontrol2:=predictedcontrol3;
    predictedcontrol3:=errorsample3/gammalyp[1,1] - gammalyp[2,1]/gammalyp[1,1];
    errorsample1:=errorsample2;
    errorsample2:=errorsample3;
  end if;
end RLS;


anxiously waiting for a help

There are 0 guests and 0 other users also viewing this topic
You are here: