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

Bug in linearize() function with symbolic linearization.

Bug in linearize() function with symbolic linearization.

Dear all,

Symbolic linearization is not working. Numerical linearization works as expected, but the symbolic one yields an incorrect result.

The system I'm using for testing is a simple harmonic oscillator. The equation of motion is

x'' + w0^2 * ( x - gnd ) = 0, with resonant frequency w0 = 2 rad/s.

The state space representation is easily calculated by defining the variables q1 =x and q2=x'. The state space vector and matrices are

q = [ q1 ]
       [ q2 ] ,

A = [ 0 ,  1 ]
       [-4 ,  0 ] ,

B = [ 0 ]
       [ 4 ] ,

C = [ 1 , 0 ] ,

D = 0.

with

Input: gnd, position of the ground
Output: q1 = x, position of mass.

The symbolic method yield the correct values for A and B, but not for C. Namely, it yields

C = [ 0 , 1 ].

In more elaborate examples, it can be seen that the value for D is also wrong, but not in this simple one.

I'm using Windows 10, OpenModelica v1.18.1 (64-bit) and OMShell.

I guess there is still a chance I'm misunderstanding the usage of the symbolic linearization, but this seems to be a bug. Is the correct forum to post this, is GitHub  more appropriate?

Any help in solving this will be appreciated.

Regards,

Fabian

Numeric linearization:

Code:


loadFile("HarmonicOscillator.mo")
clearCommandLineOptions()
linearize(HarmonicOscillator)
readFile("linearized_model.mo")

Symbolic linearization

Code:


loadFile("HarmonicOscillator.mo")
setCommandLineOptions({"+generateSymbolicLinearization"})
linearize(HarmonicOscillator)
readFile("linearized_model.mo")

Model

Code:


model HarmonicOscillator
    input Real gnd = 0.03 "Position of the ground" ;
    Real q2 "Velocity of the test mass" ;
    constant Real w0 = 2 "Resonance frequency" ;
    output Real q1 "Position of the test mass" ;
initial equation
    q1 = 0.03 "Initial position of test mass" ;
    q2 = 0.0 "Initial velocity of test mass" ;
equation
    der( q1 ) = q2 ;
    der( q2 ) = - w0 * w0 * (q1 - gnd) ;   
end HarmonicOscillator ;

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