Open2

DWSIMでの数値解析、DotNumericsの整理

田舎のケミカルエンジニア田舎のケミカルエンジニア

以下を参考
https://sourceforge.net/p/dwsim/discussion/scripting/thread/7381a728/?limit=25#c89b

DWSIMのシミュレーション内のScript manager より実効

import clr
clr.AddReference('DWSIM.MathOps.DotNumerics')

from DotNumerics import *
from DotNumerics.Optimization import *
from System import Array, Math

def BananaFunction(x):
    f = 100 * Math.Pow((x[1] - x[0] * x[0]), 2) + Math.Pow((1 - x[0]), 2)
    return f

f = OptMultivariateFunction(BananaFunction)

initialGuess = [0.0 for i in range (2)]
initialGuess[0]=0.1
initialGuess[1]=2

ival = Array[float](initialGuess)

simplex = Simplex()
minimum = simplex.ComputeMin(f, ival)

print minimum

output

Array[float]((0.99999999796052164, 0.99999999561733155))
田舎のケミカルエンジニア田舎のケミカルエンジニア

常微分方程式の解法

解こうとしている連立常微分方程式は、
\frac{dy_0}{dt} = y_1 \times y_2 \times t
\frac{dy_1}{dt} = -y_0 \times y_2
\frac{dy_2}{dt} = -0.51 \times y_0 \times y_1

import clr
clr.AddReference('DWSIM.MathOps.DotNumerics')

from DotNumerics import *
from System import Array, Math
from DotNumerics.ODE import *

yprime =[0,0,0]
def ode(t,y):
    yprime[0] = y[1] * y[2] *t
    yprime[1] = -y[0] * y[2]
    yprime[2] = -0.51 * y[0] * y[1]
    return Array[float](yprime)

func = OdeFunction(ode)
init = OdeExplicitRungeKutta45(func,3) # 
init.InitializeODEs(func,3)
x = Array[float]([0.1,0.2,0.3])
ans = init.Solve(x,0,1,15)
ans2 = []
for i in ans:
    ans2.append(i)
print ans2[-4], ans2[-3], ans2[-2], ans[-1]