tag:blogger.com,1999:blog-9690399100819247722024-02-08T02:15:18.868-08:00Mathematica Programming Some TipsKMGhttp://www.blogger.com/profile/09974135205431882018noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-969039910081924772.post-25647201875658019102013-01-09T01:40:00.001-08:002013-01-09T01:40:34.338-08:00including mathematica codeSometimes it is useful instead of creating mathematica package, and a mathematica file with some code which is included in different mathematica code.<br />
<br />
It can be easily done.<br />
<br />
1) First create the mathematica code in the inputform, with extension txt.<br />
<br />
2) Then in the main mathematica document include this file Get["file.txt"].<br />
<br />
KMGhttp://www.blogger.com/profile/09974135205431882018noreply@blogger.com0tag:blogger.com,1999:blog-969039910081924772.post-86580066975477060402013-01-09T01:28:00.004-08:002013-01-09T01:32:40.356-08:00creating mathematica packageOne can find some tips, how to create the mathematica package in web e.g.<br />
<br />
<a href="http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=FAQ_Writing_Packages">http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=FAQ_Writing_Packages</a><br />
<br />
or<br />
<a href="http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/Packages.pdf"><br />
http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/Packages.pdf</a><br />
<br />
or<br />
<br />
<a href="http://12000.org/my_notes/how_to_write_package_in_mathematica/report/report.htm">http://12000.org/my_notes/how_to_write_package_in_mathematica/report/report.htm</a><br />
<br />
<br />
My simple advice is:<br />
<br />
1) Write in one cell e.g.<br />
<br />
BeginPackage["vertexKG`",{"HighEnergyPhysics`FeynCalc`"}]<br />
<br />
Unprotect @@ Names["vertexKG`*"]; <br />
ClearAll @@ Names["vertexKG`*"]; <br />
<br />
EMv::usage = "EMvertex[mu,f1,f2,x,M]"; <br />
<br />
Begin["`Private`"]<br />
<br />
EMv[mu_, f1_, f2_, x_, M_] := Module[{temp=0}, <br />
<br />
Return[temp]]; <br />
<br />
<br />
End[]<br />
<br />
Protect @@ Names["vertexKG`*"]; <br />
EndPackage[]<br />
<br />
My package requires another package of Mathematica: HighEnergyPhysics`FeynCalc`, it is a second argument of BeginPackage.<br />
<br />
After BeginPackage I write the declaration of the functions, and in the private part the definitions.<br />
<br />
2) Then in cell menu one must choose Initialization Cell<br />
<br />
3) Save as file.m<br />
<br />
3) Load as Get["D:\\myMathematicaLibries\\file.m"]<br />
KMGhttp://www.blogger.com/profile/09974135205431882018noreply@blogger.com0tag:blogger.com,1999:blog-969039910081924772.post-4533654251855832672013-01-09T01:04:00.001-08:002013-01-09T01:33:41.097-08:00Remote runningIn case of the logn-time calculations, it is useful to run a mathematica program on some remote Linux server. <br />
<br />
My way of doing it is the following:<br />
<br />
1) it is convenient to edit the program code in the notebook form.<br />
<br />
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<br />
<br />
3) Save as .txt file<br />
<br />
4) put the .txt file on the remote Linux machine<br />
<br />
5) run mathematica kernel: math < file.txt > output.txt<br />
<br />
6) In the output.txt the output is recorded.<br />
KMGhttp://www.blogger.com/profile/09974135205431882018noreply@blogger.com0