Open2
DWSIMでの数値解析、DotNumericsの整理
以下を参考
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))
常微分方程式の解法
解こうとしている連立常微分方程式は、
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]