I am trying to make a windows C# form which uses some functions that I wrote inside Mathematica.

Suppose that we have the following package:


SecondDegre[a_, b_, c_] := Module[{delta, x1, x2},
     x1=(-b + delta^0.5)/(2 a);
     x2=(-b - delta^0.5)/(2 a);

I already tested this package in Mathematica - it works, successfully made a connection C# to Mathematica by adding reference and tested this example:

using Wolfram.NETLink;

private void button1_Click(object sender, EventArgs e)
     Expr symbolPlus = new Expr(ExpressionType.Symbol,"Range");
     Expr e1 = new Expr(symbolPlus, 1, 4,1);
     IKernelLink ml = MathLinkFactory.CreateKernelLink();

     // ml is a KernelLink
     string result = ml.EvaluateToOutputForm(e1, 0);
     textBox3.Text = result ;


The output after execution is:


My question is : How can I run the Mathematica package inside C# in order to use the SecondDegre like i have used the Range in the previous example?


I think that you can just do a Get[] or Needs[] to load the package...BTW test this without .NetLink first to make sure you have the directory issues figured out

After your package is loaded, you should be able to evaluate SecondDegre[] just like accessing functions inside packages from inside Mma.

Ref: http://reference.wolfram.com/workbench/index.jsp?topic=/com.wolfram.eclipse.help/html/tasks/applications/packages.html

| improve this answer | |
  • $\begingroup$ I already tested this before, and unfortunately it doesn't work! $\endgroup$ – Bob Mar 31 '15 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.