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

issue generating triangular wave function in Modelica

issue generating triangular wave function in Modelica

same question in stackoverflow

I'm trying to create a model where one Modelica variable is a triangular wave of another variable. First I tried the floor() function as below:

Code:


model test1
  final constant Real pi=2*Modelica.Math.asin(1.0);
  parameter Real b = 1;
  parameter Real a = 1;
  Real x,p,u;
equation
  if sign(sin(x*pi/b))>=0 then
    p=a*(x-b*floor(x/b));
  else
    p=a*(b-(x-b*floor(x/b)));
  end if;
  x=time;
  u = floor(x/b);
end test1

(x=time; is arbitrary so the model compiles)

but the result is weird, as you can see below
https://i.stack.imgur.com/HtrjV.png

zoom in:

https://i.stack.imgur.com/kLvLc.png

somehow 0.005 seconds before the next step floor function behaves unexpectedly and becomes a linear function ending by the next value.

https://i.stack.imgur.com/8lv8u.png

then I tried the ceil() function. everything seemed right till I realised the same problem happens with ceil() function at other values (e.g. x=13)

I would appreciate if you could:

1. help me understand why this "glitch" happens and if it is intentional by design or a bug?

2. how I can fix this?

3. are there any alternatives to create a triangular wave function?

P.S. I am using this "wave function" to model the interaction between two jagged bodies

Edited by: foadsf - Feb-09-17 15:44:51
There are 0 guests and 0 other users also viewing this topic
You are here: