23.2.6 Procedure and Examples for Using Mathematica Link

In this page, we will talk about the procedure of using Origin's Mathematica Link, and also include examples. The version of Mathematica used here is Mathematica 10.0.

Start Mathematica Link in Origin

Before launching the tool, you will need to set up the Kernel configuration in Mathematica to link to Origin's kernel OSequencer.exe. Refer to this page for detailed steps.

Examples

Before attempting these examples, please launch the Mathematica Link in Origin using the procedure in the previous section.

Example 1

This example sends worksheet data to and receive from Methematica

  1. Import the data <Origin Installation Directory>/Samples/Signal Processing/fftfilter1.DAT to a new worksheet by using the system default theme, in order to make sure that the workbook name and worksheet name are renamed with the file name, fftfilter1.
  2. Activate the Origin Link for Mathematica dialog, and go to the Column tab. In the Send Column group, set Mathematica Variable and Orgin Dataset as raw and [fftfilter1]fftfilter1!col(b) respectively.
    Mathematica Link Column Send.png
  3. Click the Send button to send the second column of data to Mathematica.
  4. Go to the Evaluate tab, type the following two lines for Input
    temp=Fourier[raw]
    realpart=Re[temp]
  5. Click the Evaluate button to get the results.
    Mathematica Link Evaluate.png
  6. Go to the worksheet, click the Add New ColumnsMathematica Link Add Col Button.png button in the Standard toolbar to add column C to the worksheet.
  7. Go back to the Origin Link for Mathematica dialog and activate the Column tab. Set the Receive Column group as:
    Mathematica Variable: realpart
    Origin Dataset: [fftfilter1]fftfilter1!col(c)
    Mathematica Link Column Receive.png
  8. Click the Receive button, and the result will be placed into column C of the worksheet.
    Mathematica Link Worksheet Result.png

Example 2

This example sends and receives matrix data to and from Mathematica.

  1. Open the matrix <Origin Installation Directory>/Samples/Matrix Conversion and Gridding/2D Gaussian.ogm.
  2. Activate the Origin Link for Mathematica dialog and go to the Matrix tab. In the Send Matrix group, set Mathematica Variable and Origin Matrix as mat and [MBook1]Data!1 respectively.
    Mathematica Link Matrix Send.png
  3. Click the Send button.
  4. Open Mathematica if not already started.,Create a new notebook. Select from menu Evaluation: Notebook's Kernel, make sure the kernel "OSequencer" is selected.. Now the current notebook of Mathematica can communicate with Origin.
  5. Enter the following script
    invmat = Inverse[mat]
    and execute it.
    Mathematica Link Mathematica.png
  6. Go back to Origin. Add a new matrix object to Data matrix sheet. Click the D icon at the top-right corner of Data matrix sheet. Select Add to add a new object.
  7. Activate the Origin Link for Mathematica dialog, and set the Receive Matrix group as:
    Mathematica Variable: invmat
    Origin Matrix: [MBook1]Data!2
    Mathematica Link Matrix Receive.png
  8. Click the Receive button, you will get the inverse of the original matrix.
    Mathematica Link Matrix Result.png

Example 3

This example creates and plots a user function defined in Mathematica.

  • Open Mathematica if not already started.,Create a new notebook. Select menu menu Evaluation: Notebook's Kernel, make sure the kernel "OSequencer" is selected.. Now the current notebook of Mathematica can communicate with Origin.
  • Define a function as follow:
    f1[x_] := (FresnelS[x] + 1/2)^2 + (FresnelC[x] + 1/2)
  • Go back to Origin. In the Function tab of Origin Link for Mathematica dialog, specify the formula and the curve range and number of data points as follow

    f(x) =: f1[x^2+2]
    From: 0
    To: 10
    Points: 2000

    Mathematica Link Function.png
  • Click the Plot button, the user-defined function is plotted.
    Mathematica Link Function Plot.png