Numerical Library

The numerical library that IronPython supports is Math.net. This library is available for use with ACT and is installed in the following directory:

C:\Program Files\ANSYS Inc\v242\Addins\ACT\bin\Win64\MathNet.Numerics.dll


Note:  Because Numpy and SciPyY are numerical libraries supported by Python rather than IronPython, they cannot be used with ACT.


The following code sample provides three examples for using Math.net:

import clr
import System
import os
clr.AddReferenceToFileAndPath(​​"C:\\Program Files\\ANSYS Inc\\v242\\Addins\\ACT\\bin\\Win64\\MathNet.Numerics.dll")

# Example 1​​
import MathNet
from MathNet.Numerics.LinearAlgebra import *
V=Vector[System.Double].Build
M=Matrix[System.Double].Build

m = M.Random(3,4)
v = V.Random(3)

r=v*m
print r

# Example 2​​
import MathNet.Numerics.LinearAlgebra as la

from System import Array as sys_array
def array(*x): return sys_array[float](x) #float is equivalent to .Net double

A = la.Double.Matrix.Build.DenseOfRowArrays(
   array(3, 2,-1),
   array(2,-2,4),
   array(-1,.5,-1)
)

b = la.Double.Vector.Build.DenseOfArray(array(1, -2, 0))
x = A.Solve(b)

print x

# Example 3​​
A1 = la.Double.Matrix.Build.DenseOfRowArrays(
   array(3.0, 4.0, -1.0, 0.0),
   array(4.0, 5.0, 0.0, -1.0),
   array(5.0, 6.0, 0.0, 0.0),
   array(6.0, 7.0, 0.0, 0.0)
)
b1 = la.Double.Vector.Build.DenseOfArray(array(0, 0, 20, 0))
x1 = A1.Solve(b1)

print x1