- Index
- » Programming
- » Modelica Language
- » Random number generation
Page Start Prev 1 Next End
Random number generation
Random number generation
Jul-03-13 13:14:39
I am trying to generate random noise but get strange results. Code is based on Kalman.onb example (which does not work either. The function I use and the modle to test it are:
Code:
record SEEDINFO
Real s1;
Real s2;
Real s3;
end SEEDINFO;
function MathRandom
input SEEDINFO si;
input Real tim;
output Real x;
output SEEDINFO so;
algorithm
so.s1 := abs( rem( (171*si.s1*exp( mod(tim-11,tim+13) ) ), 30269) );
so.s2 := abs( rem( (172*si.s2*exp( mod(tim-5,tim+7) ) ), 30307) );
so.s3 := abs( rem( (170*si.s3*exp( mod(tim-23,tim+76) ) ), 30323) );
if so.s1 < 1e-4 then
so.s1 := 1.0;
end if;
if so.s2 < 1e-4 then
so.s2 := 1.0;
end if;
if so.s3 < 1e-4 then
so.s3 := 1.0;
end if;
x := rem((so.s1/30269.0 +so.s2/30307.0 + so.s3/30323.0),1.0);
end MathRandom;
model test_MathRandom
output Real y(start=0.0);
parameter Real dtSample = 0.1;
protected
SEEDINFO s(s1(start=-10), s2(start=20), s3(start=30));
Real x(start=0.0);
algorithm
(x,s):=MathRandom(s,time);
equation
when sample(0.0, dtSample) then
y = x;
end when;
end test_MathRandom;
The output starts somewhere at 1.0e+21.
The function when used in OMNotebook gives the expected results.
Any ideas?
Edited by: eypma - Jul-03-13 16:06:22
Page Start Prev 1 Next End
- Index
- » Programming
- » Modelica Language
- » Random number generation
There are 0 guests and 0 other users also viewing this topic