C#-解决复杂的ODE集 [英] c# - solving complexed ODE set

查看:132
本文介绍了C#-解决复杂的ODE集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介 某些ODE集无法解析解决.在这种情况下,有很多众所周知的方法,尤其是在像MATLAB这样的典型科学软件中.只要您坚持使用,一切都很好.但是,如果您尝试将此功能移植到其他环境,则问题就开始了.就我而言,我需要用C#.

Introduction Some sets od ODE can't be solved analytically. In this case there are plenty of well-know methods, especially in typical scientific software like MATLAB. As long as you stay with it, all is fine. But the problem starts if you try to port this functionality to other environment. In my case I need it in C#.

一些详细信息 当然,ODE有一些C#库,但是在大多数情况下(至少在我所熟悉的情况下),它的功能是非常有限的.让我们看一下OSLO库,这是一个示例查询:

Some details Of course, there are some C# libs for ODE's but in most cases (at least in this which i'm familiar with), there are quite limited. Let's look at OSLO library, here's an example query:

var sol = Ode.RK547M(0, new Vector(5.0, 1.0),
(t, x) => new Vector(
x[0] - x[0] * x[1],
-x[1] + x[0] * x[1]));

如您所见,它不允许提供任何其他支持的非OD方程,也不允许提供嵌入式算法.如果我们例如必须解决以下设置,这将受到限制:

As you can see, it doesn't allow to provide any additional support non-OD equations, nor embedded algorithms. It's a bit to limited if we for example have to solve setup like this:

a=x*2+7
b=y*x+3
c- need to be calculated with external algorithm basing and "b" and "x"
dx/dt=x - xy + a + c
dx/dt=-y +xy + b

在上述情况下,lib似乎效率不高.在C ++中,我通过boost使用odeint库.我可以这样定义一个结构:

In this case presented above lib seems to be not efficient. In C++ I use odeint library by boost. I can define a struct like this:

struct solveODE
{
    void operator()( const vector_type &y , vector_type &ODE , const double t )
    {
        double x=y[0];
        double y=y[1];
        a=x*2+7;
        b=y*x+3;
        additional_solve(b, x);
        ODE[0]=x - xy + a + c;
        ODE[1]=-y +xy + b;
        }
};

并这样称呼它:

integrate_const(make_dense_output<stepper_type>( 1E-12, 1E-6 ),
                    solveODE(),
                    y, 0.0, t_end, dt ,
                    std::bind(&calc::printResults , std::ref(*this) , pl::_1 , pl::_2));

问题

问题是,除了解决严格的颂歌集之外,我还将为哪个C#库提供此功能?性能非常重要,因为节点集可能包含25个以上的方程式+许多支持代数方程式.更具体地说-我什至无法计算分析雅可比行列式,因为它在时间上不是恒定的,因此潜在求解器的选择受到限制.

The question is which library for C# will me provide this functionality, in addition with solving stiff ode sets? The performance is quite important as ode set may contain 25+ equations + a lot of support algebraic equations. To be more specific - I can't calculate even analytic Jacobian as it will be not constant in time, so the selection of potential solvers is limited.

推荐答案

您应该可以使用

var sol = Ode.RK547M(0, new Vector(5.0, 1.0),
    (t, u) => {
        double x=u[0], y=u[1];
        double a=x*2+7, b=y*x+3;
        double c = additional_solve(b, x);
        return new Vector(
            x - x*y + a + c,
            -y +x*y + b
        );
     });

作为lambda委托定义的长形式,即使用x => x*x表示x => { return x*x; }的缩写,delegate(x) { return x*x; }的缩写,依此类推.

as the long form of a lambda delegate definition, that is, using that x => x*x is short for x => { return x*x; } which is short for delegate(x) { return x*x; } and so on.

这篇关于C#-解决复杂的ODE集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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