środa, 9 stycznia 2013

including mathematica code

Sometimes it is useful instead of creating mathematica package, and a mathematica file with some code which is included in different mathematica code.

It can be easily done.

1) First create the mathematica code in the inputform, with extension txt.

2) Then in the main mathematica document include this file Get["file.txt"].

creating mathematica package

One can find some tips, how to create the mathematica package in web e.g.

http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=FAQ_Writing_Packages

or

http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/Packages.pdf


or

http://12000.org/my_notes/how_to_write_package_in_mathematica/report/report.htm


My simple advice is:

1) Write in one cell e.g.

BeginPackage["vertexKG`",{"HighEnergyPhysics`FeynCalc`"}]

Unprotect @@ Names["vertexKG`*"];
ClearAll @@ Names["vertexKG`*"];

EMv::usage = "EMvertex[mu,f1,f2,x,M]";

Begin["`Private`"]

EMv[mu_, f1_, f2_, x_, M_] := Module[{temp=0},

Return[temp]];


End[]

Protect @@ Names["vertexKG`*"];
EndPackage[]

My package requires another package of Mathematica: HighEnergyPhysics`FeynCalc`, it is a second argument of BeginPackage.

After BeginPackage I write the declaration of the functions, and in the private part the definitions.

2) Then in cell menu one must choose Initialization Cell

3) Save as file.m

3) Load as Get["D:\\myMathematicaLibries\\file.m"]

Remote running

In case of the logn-time calculations, it is useful to run a mathematica program on some remote Linux server.

My way of doing it is the following:

1) it is convenient to edit the program code in the notebook form.

2) then rewrite the code into InputForm, it can be done by converting all cells into InputForm, crt-a, main menu -> cell -> convert to InputForm

3) Save as .txt file

4) put the .txt file on the remote Linux machine

5) run mathematica kernel: math < file.txt > output.txt

6) In the output.txt the output is recorded.