1
$\begingroup$

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:

BeginPackage["second`"];
Begin["`Private`"];

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

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.WaitAndDiscardAnswer();

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

     ml.Close();
}

The output after execution is:

{1,2,3,4}

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ I already tested this before, and unfortunately it doesn't work! $\endgroup$
    – Bob
    Commented Mar 31, 2015 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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