尝试生成随机变量时未找到翻译错误类

尝试生成随机变量时未找到翻译错误类

本文介绍了尝试生成随机变量时未找到翻译错误类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循 这个例子 生成随机时间函数:

I'm trying to follow this example to generate a random function of time:

model testData

  extends Modelica.Icons.Example;

  parameter Real k = 1.0;
  Real theta1;
  Real theta2;
  parameter Real tau = 1.0;

  parameter Modelica.SIunits.Period samplePeriod = 0.05;
  parameter Integer globalSeed = 30020;
  output Real omega1;

algorithm
  when initial() then
    state1024 := Generators.Xorshift1024star.initialState(localSeed, globalSeed);
    omega1     := 0;
  elsewhen sample(0,samplePeriod) then
    (omega1,state1024) := Generators.Xorshift1024star.random(pre(state1024));
  end when;

public
  parameter Integer id = Utilities.initializeImpureRandom(globalSeed);
  discrete Real rImpure;
  Integer iImpure;
algorithm
  when initial() then
    rImpure := 0;
    iImpure := 0;
  elsewhen sample(0,samplePeriod) then
    rImpure := Utilities.impureRandom(id=id);
    iImpure := Utilities.impureRandomInteger(
          id=id,
          imin=-1234,
          imax=2345);
  end when;

initial equation
  theta1 = 0;
  theta2 = 0;
  der(theta2) = 0;

equation
  der(theta1) = omega1;
  der(der(theta2)) = tau + k * (theta1 - theta2);

annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.02));

end testData;

但是,我收到错误消息:

however, I get the error message:

翻译错误

在范围 testData 中找不到类 Utilities.initializeImpureRandom(查找函数或记录).

Class Utilities.initializeImpureRandom not found in scope testData (looking for a function or record).

翻译错误

展平模型 testData 时出错

Error occurred while flattening model testData

如果您能帮助我了解问题所在以及如何解决,我将不胜感激.

I would appreciate if you could help me understand what is the problem and how I can solve it.

推荐答案

您丢失了一些导入,见下文,一些变量声明,并且您使用了 der(der(...)) 这不起作用,您需要将内部 der 绑定到一个变量.下面这个模型编译仿真(不知道结果好不好).

You were missing some imports, see below, some variable declarations and you were using der(der(...)) which doesn't work, you need to bind the internal der to a variable. This model below compiles and simulates (I don't know if the results are fine or not).

model testData

  extends Modelica.Icons.Example;
  import Modelica.Math.Random.Generators;
  import Modelica.Math.Random.Utilities;

  parameter Real k = 1.0;
  Real theta1;
  Real theta2;
  Real der_theta2;
  parameter Real tau = 1.0;

  parameter Modelica.SIunits.Period samplePeriod = 0.05;
  parameter Integer globalSeed = 30020;
  parameter Integer localSeed = 614657;
  output Real omega1;
  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,samplePeriod) then
    (omega1,state1024) := Generators.Xorshift1024star.random(pre(state1024));
  end when;

public
  parameter Integer id = Utilities.initializeImpureRandom(globalSeed);
  discrete Real rImpure;
  Integer iImpure;
algorithm
  when initial() then
    rImpure := 0;
    iImpure := 0;
  elsewhen sample(0,samplePeriod) then
    rImpure := Utilities.impureRandom(id=id);
    iImpure := Utilities.impureRandomInteger(
          id=id,
          imin=-1234,
          imax=2345);
  end when;

initial equation
  theta1 = 0;
  theta2 = 0;
  der(theta2) = 0;
  der_theta2 = 0;

equation
  der(theta1) = omega1;
  der(theta2) = der_theta2;
  der(der_theta2) = tau + k * (theta1 - theta2);

annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.02));

end testData;

这篇关于尝试生成随机变量时未找到翻译错误类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 21:42