非线性代数方程的初始猜测 [英] Initial guesses for nonlinear algebraic eqtns

查看:50
本文介绍了非线性代数方程的初始猜测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非线性代数方程组需要求解.如何使用计算值(具有连续时间可变性)作为解变量的初始猜测,而不是使用参数作为起始值?初始方程部分可以用于此目的吗?

I have a system of nonlinear algebraic equations to solve. How can I use computed values (with continuous-time variability) as initial guess for the variables of solution instead of using parameters as start values? Can initial equation section be used for this purpose?

我创建了一个测试模型来解释这个问题:

I have created a test model to explain the issue:

model Teststartvalue
  Real value1=1000;//calculated by some model
  Real value2=-1000;//calculated by some model
  parameter Real InputValue = 100;//Input to model
  Real StartValue=if InputValue < value2 then 1.8 elseif InputValue > value1 then 2.8 else 0.5;
  Real x(start=0.5);
//Desired code
//  Real x(start=StartValue);
equation
  (x-1)*(x-2)*(x-3)=0;
//  x^3-(6*x^2)+(11*x)-6=0;
end Teststartvalue;

目的是根据一些计算提供x"的初始猜测.我如何在 openmodelica 中实现这一点?

The intention is to provide the initial guess for "x" based on some calculation. How can I achieve this in openmodelica?

推荐答案

据我所知,start 属性只能采用具有常量或参数可变性的表达式(参见 Modelica Specification 3.4 Section 3.8).因此,我想到的唯一真正的解决方案是有点黑客:

As far as I know the start attribute can only take expression with either constant- or parameter variability (see Modelica Specification 3.4 Section 3.8). Therefore the only real solution that comes to my mind is a bit of a hack:

  • 将用于起始值的参数的固定属性(在您的示例中为 StartValue)设置为 false
  • 计算初始方程中的值

这将导致:

model TestStartValue
  Real value1=1000;//calculated by some model
  Real value2=-1000;//calculated by some model
  parameter Real InputValue = 100;//Input to model
  final parameter Real StartValue(fixed=false);
  Real x(start=StartValue);

initial equation 
  StartValue=if InputValue < value2 then 1.8 elseif InputValue > value1 then 2.8 else 0.5;

equation 
  (x-1)*(x-2)*(x-3)=0;
end TestStartValue;

不确定这是否适用于所有工具及其未来版本!我实际上不认为这是打算以这种方式使用.这也可能导致稍后出现问题,因为通常假设参数是在模拟开始之前设置的,而不是在其初始化期间...

Not sure this will work in all tools and in future versions thereof! I actually don't think this is intended to be used this way. Also this could cause problems later on as parameters are usually assumed to be set before the simulation starts, not during its initialization...

另一种选择是使用初始方程,它应该给出如下内容:

Another alternative would be to use the initial equation, which should give something like:

model TestStartValueInitEq
  Real value1=1000;//calculated by some model
  Real value2=2000;//calculated by some model
  parameter Real InputValue = 100;//Input to model
  Real x;

initial equation 
  if InputValue < value2 then
    pre(x)-2=0;
  elseif InputValue > value1 then
    pre(x)-3=0;
  else
    pre(x)-1=0;
  end if;

equation 
  (x-1)*(x-2)*(x-3)=0;
end TestStartValueInitEq;

此解决方案的缺点是,初始方程实际上旨在设置状态变量的值.对于这些初始值可以自由选择(或多或少),因为在初始化时没有确定它的等式.这不是这里的情况,它会在初始化期间为 x 提供多个方程,这将制动模型.为了在 Dymola 中避免这种情况, pre() 有帮助(不确定它是否在其他工具中).这会导致冗余一致的初始条件".Dymola 可以处理.对于冗余的方程,它们需要给出相同的结果.因此,您不能像在原始代码中那样对结果使用估计值,这就是我在第二个示例中更改它们的原因.

The drawback with this solution is, that an initial equation is actually intended to set the value for state variables. For these the initial value can be chosen freely (more or less) as there is no equation determining it at the initialization. This is not the case here, which will give multiple equations for x during initialization which will brake the model. To avoid this in Dymola the pre() helps (not sure it does in other tools). This then results in "Redundant consistent initial conditions." which Dymola can handle. For the equations to be redundant, they need give the same result. Hence you cannot use estimates for the result as in you original code, which is why I changed them for the second example.

这两种解决方案对我来说仍然不完美.如果有任何其他解决方案,请添加它...

Still both solutions seem imperfect to me. If there is any other solution please add it...

这篇关于非线性代数方程的初始猜测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆