Skip to content

Instantly share code, notes, and snippets.

@Foadsf
Created September 11, 2019 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Foadsf/b0447e8d772b16fe8c78ece99f21e7f5 to your computer and use it in GitHub Desktop.
Save Foadsf/b0447e8d772b16fe8c78ece99f21e7f5 to your computer and use it in GitHub Desktop.
modelica code for this question https://stackoverflow.com/q/57886368/4999991
model testData
extends Modelica.Icons.Example;
import Modelica.Math.Random.Generators;
import Modelica.Math.Random.Utilities;
parameter Real k = 50.0;
parameter Real J = 0.001;
Real theta1;
Real theta2;
Real omega2;
parameter Integer globalSeed = 30020;
parameter Integer localSeed = 614657;
parameter Modelica.SIunits.Period samplePeriod1 = 0.05;
output Real omega1;
parameter Modelica.SIunits.Period samplePeriod2 = 0.17;
output Real tau;
protected
discrete Integer state1024[33](each start=0, each fixed = true);
algorithm
when initial() then
state1024 := Generators.Xorshift1024star.initialState(localSeed, globalSeed);
omega1 := 0;
elsewhen sample(0, samplePeriod1) then
(omega1, state1024) := Generators.Xorshift1024star.random(pre(state1024));
omega1 := (omega1 - 0.5) * 13;
end when;
when initial() then
state1024 := Generators.Xorshift1024star.initialState(localSeed, globalSeed);
tau := 0;
elsewhen sample(0, samplePeriod2) then
(tau, state1024) := Generators.Xorshift1024star.random(pre(state1024));
tau := (tau - 0.5) * 3;
end when;
initial equation
theta1 = 0;
theta2 = 0;
der(theta2) = 0;
equation
der(theta1) = omega1;
der(theta2) = omega2;
J * der(omega2) = tau + k * (theta1 - theta2);
annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.02));
end testData;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment