1

This is sort of related to my earlier question, but different. I can't figure out how to give MathLink function options without using Evaluate(), etc. For example, I have the following C# code:

ml.PutFunction("Abs",1);
ml.PutFunction("Fourier",2);
ml.Put(data); //data = double[]
ml.Put("FourierParameters->{-1,1}");

It doesn't work. It puts the FourierParameters part as a literal string, and not an option. I tried creating an Expr with that string and putting that, but that failed too. Is this even possible to do in .NETLink?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
PrinceBilliard
  • 181
  • 1
  • 17

2 Answers2

2

Following this example page, seems the option must be entered with PutSymbol, and you need to add a "Rule" PutFunction.

Resulting in something like (not tested):

ml.PutFunction("EvaluatePacket", 1);
ml.PutFunction("Abs",1);
ml.PutFunction("Fourier",2);
ml.Put(data); //data = double[]

ml.PutFunction("Rule", 2);
ml.PutSymbol("FourierParameters");
ml.PutFunction("List", 2);
ml.Put(-1); 
ml.Put(1); 
ml.EndPacket();
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • I just tested it and it works perfectly. Thanks alot; this was a piece of a bigger puzzle that has now been solved. – PrinceBilliard May 04 '11 at 17:49
  • 1
    @Prince so consider it a little miracle ... I never worked with NETLink, and I wasn't able to test the code :) – Dr. belisarius May 04 '11 at 17:59
  • I am just starting to program using this methodoligy and I can't find any documentation of what functions I can use with "putFunction" and what arguments need to go with them. For example i need to do a fourier transform and maybe it is because of my lack of experience in math but I don't know what that 2 stands for. Can someone point me to a API or list of possible functions I can use with PutFunction and info about them? – kenetik Aug 14 '12 at 16:44
  • @kenetik You should post that as a question – Dr. belisarius Aug 14 '12 at 16:58
  • @kenetik Anyway, you should look at this http://reference.wolfram.com/mathematica/ref/FourierParameters.html – Dr. belisarius Aug 14 '12 at 17:02
  • I am very hesitant about posting questions lately, the last 3 questions I posted have recieved such negative feedback / downvotes. However I beleive I have figured out this solution, and thank you for your answer and not berrating me. – kenetik Aug 15 '12 at 18:17
  • @kenetik Please check the new Mathematica Q&A site http://mathematica.stackexchange.com – Dr. belisarius Aug 15 '12 at 23:11
1

I would do this using high level wrappers. For example, one could write a Mathematica function called MyFunction, using all the conveniences of Mathematica, that calls one of several low level, mathlink functions say myFunction1, myFunction2, etc. Which mathlink function to call would be based on standard option handling techniques within Mathematica.

Mark McClure
  • 4,862
  • 21
  • 34
  • I'd like to avoid the high-level wrappers because, long story short, the numbers I'm getting out of MathLink appear to be very wrong, and I'm making sure that the problem isn't my parsing of them from, say, InputForm. And I unfortunately only know MathLink from the C# end :) – PrinceBilliard May 04 '11 at 17:41
  • @Prince Assuming that you want to pass Mathematica commands from C back into Mathematica, then I think that belisarius nailed it from the C# end. That really requires a rather strong understanding of Mathematica expression trees, however, so I don't see how to get around that level of understanding of Mathematica. – Mark McClure May 04 '11 at 17:50