PrinceBilliard
PrinceBilliard

Reputation: 181

Setting ComplexType in MathLink

I have another one. I tried to use ml.ComplexType = System.Type.GetType("Complex"); in C# with the Mathematica MathLink, but when I tried to read the numbers with GetComplexArray, it threw an exception stating that I must use the method IMathLink.SetComplexType(), which does not appear to exist.

Is there any way to do this without parsing strings, since I can't for the life of me do that correctly?

Upvotes: 0

Views: 177

Answers (2)

PrinceBilliard
PrinceBilliard

Reputation: 181

For anyone else's reference, I discovered the answer to this one on my own.

What you do is create a dummy instance of any class that has the necessary properties/methods (such as System.Numerics.Complex), here named myVar. Now assuming ml is an instance of IKernelLink, call

ml.ComplexType = myVar.GetType();

You can then use ml.GetComplex() or ml.GetComplexArray().

Upvotes: 1

Mark McClure
Mark McClure

Reputation: 4964

The documentation for SetComplexType is here: http://reference.wolfram.com/mathematica/NETLink/ref/SetComplexType.html. You can also find this by pasting "NETLink/ref/SetComplexType" into the Mathematica documentation center. Both these sources indicate that you must execute Needs["NETLink]" prior to use in Mathematica.

Upvotes: 1

Related Questions