Intergral Functions - Dynamo

Is there any way to integrate a function within dynamo/within a python script?

I have used the scipy package within python before (which can accomplish what I want to do), but did not know if there was any way to import this package into a python script within dynamo.

So I found this link:

It looks like this might not work. I am not too familiar with why though. Sounds like IronPython and Scipy may not jive?

Short answer:
Maybe, but not with NumPy. Try Math.NET

Long answer:
A lot of NumPy/SciPy is written in C, and since IronPython is a .NET implementation of Python, it’s incompatible with the standard NumPy and SciPy modules. There is a version of Numpy/SciPy written specifically for use with IronPython, but I haven’t been able to get it to work in Dynamo. I can successfully import it in the ipy console, though:

The ironpkg-1.0.0.py script is no longer on Enthought’s website (although the .egg is available), but someone has it on one of their GitHub repositories. Download the eggs manually from here and put them in a new folder.

Additional steps can be found here (skip steps 1 and 2)

This is as far as I got trying to import NumPy:

import clr
import sys
import System
sys.path.append('C:\\Program Files (x86)\\IronPython 2.7')
sys.path.append('C:\\Program Files (x86)\\IronPython 2.7\\DLLs')
sys.path.append('C:\\Program Files (x86)\\IronPython 2.7\\Lib')
sys.path.append('C:\\Program Files (x86)\\IronPython 2.7\\Lib\\site-packages')

clr.AddReference('NumpyDotNet')
# clr.AddReferenceToFile('mtrand.dll')

ipy_ver = sys.version[:5]
net_ver = System.Environment.Version

import numpy as np
OUT = 'IronPython {ipy} on .NET {net} (32-bit)'.format(ipy=ipy_ver, net=net_ver)
2 Likes

I will puruse math.net to see if it has a good integral function.
Looks like there is something good out there:
https://numerics.mathdotnet.com/Integration.html

Do you have any references on how to import math.net into the python dynamo node?
Still somewhat new to this and help on the import/setup process to import the math.net integration function would be helpful.

Thanks again for your help!

See this post. There’s probably a cleaner way to import it, but it should work.

Math.NET deve estar instalado primeiro

An example how to import Math.NET into Iron Python. I test it and works fine.

import sys
sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")
sys.path.append("D:\\Dropbox\\Dynamo Workspaces\\Nuget\\MathNet.Numerics.4.5.1\\lib\\net40\\MathNet.Numerics.dll")

import os

# Import 
from clr import AddReferenceToFileAndPath as addref
location = os.path.join(os.path.expanduser("~"),
'D:\\Dropbox\\Dynamo Workspaces\\Nuget\MathNet.Numerics.4.5.1\\lib\\net40\\MathNet.Numerics.dll')
addref(location)

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)


OUT = x
1 Like