{"id":12461,"date":"2020-03-09T16:47:00","date_gmt":"2020-03-09T08:47:00","guid":{"rendered":"https:\/\/nusit.nus.edu.sg\/support\/faqpage\/maple-faq-copy\/"},"modified":"2021-12-07T12:50:04","modified_gmt":"2021-12-07T04:50:04","slug":"mathematica-faq","status":"publish","type":"post","link":"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/","title":{"rendered":"FAQ: Mathematica"},"content":{"rendered":"<section class=\"wpb-content-wrapper\"><p>[vc_row css=&#8221;.vc_custom_1540890245444{padding-top: 0px !important;padding-bottom: 0px !important;}&#8221;][vc_column][vc_row_inner css=&#8221;.vc_custom_1540890707324{margin-bottom: 60px !important;}&#8221;][vc_column_inner][vc_column_text]<\/p>\n<h2><span style=\"color: #ef7c00\">FAQ: <\/span><span class=\"black\" style=\"color: #003d7c\">Mathematica<\/span><\/h2>\n<p>[\/vc_column_text][\/vc_column_inner][\/vc_row_inner][vc_toggle title=&#8221;1. How to start Mathematica&#8221; style=&#8221;round&#8221; size=&#8221;sm&#8221;]<\/p>\n<p align=\"justify\">Mathematica has two interfaces: command line interface and Graphical User Interface (GUI).<\/p>\n<p align=\"justify\">To start the command line interface, enter command<\/p>\n<pre class=\"no-style hpc-codestyling\">math<\/pre>\n<p align=\"justify\">and to start the graphics GUI, enter command<\/p>\n<pre class=\"no-style hpc-codestyling\">mathematica<\/pre>\n<p align=\"justify\">GUI Mathematica is supported on MobileVisLab only. Command line based Mathematica can be run on clusters Atlas4\/5\/6\/7 as well.<\/p>\n<p>[\/vc_toggle][vc_toggle title=&#8221;2. How to run large and long CPU hours Mathematica jobs?&#8221; style=&#8221;round&#8221; size=&#8221;sm&#8221;]<\/p>\n<p align=\"justify\">Mathematica programs that are large and need longer computing time to run can be submitted to LSF batch queue(s) to run as batch mode. To do this, firstly you need to open the notebook (*.nb) file in a Mathematica GUI, and then save the file as a plain text file (*.txt) via<\/p>\n<p><strong>File\u00a0<\/strong><strong>\u21d2 Save As\u2026 \u21d2\u00a0<\/strong>Choose<strong>\u00a0Plain Text (*.txt)\u00a0<\/strong>as<strong>\u00a0Files of type:\u00a0<\/strong><strong>\u21d2<\/strong><strong>\u00a0Save.<\/strong><\/p>\n<p>When you have the text file (e.g. prog1.txt), you can submit it to be executed in a batch computing queue. If the program takes less than 4GB memory, you can submit it to run in queue \u201cserial\u201d using the below job submission script (e.g.\u00a0 pbs_job1.txt):<\/p>\n<pre class=\"no-style hpc-codestyling\">#!\/bin\/bash\r\n\r\n#PBS -P Project_mathematica\r\n#PBS -q serial\r\n#PBS -l select=1:ncpus=1:mem=5GB\r\n#PBS -j oe\r\n#PBS -N Job_mathematica\r\n\r\ncd $PBS_O_WORKDIR;   ## This line is needed, do not modify.\r\n\r\n##--- Put your exec\/application commands below ---\r\n## If your mathematica program is &lt; prog1.txt &gt;.\r\n\r\nmath &lt; prog1.txt<\/pre>\n<p align=\"justify\">You shall save the &#8220;prog1.txt&#8221; and &#8220;pbs_job1.txt&#8221; in the same working folder, then you can submit the job via &#8220;qsub&#8221; command as:<\/p>\n<pre class=\"no-style hpc-codestyling\"># qsub pbs_job1.txt\"<\/pre>\n<p align=\"justify\">If the program uses more than 4GB memory, you can submit it to run in large memory queues &#8220;openmp&#8221;. The job submission script will be:<\/p>\n<pre class=\"no-style hpc-codestyling\">#!\/bin\/bash\r\n\r\n#PBS -P Project_mathematica\r\n#PBS -q openmp\r\n#PBS -l select=1:ncpus=1:mem=20GB\r\n#PBS -j oe\r\n#PBS -N Job_mathematica\r\n\r\ncd $PBS_O_WORKDIR;   ## This line is needed, do not modify.\r\n\r\n##--- Put your exec\/application commands below ---\r\n## If your mathematica program is &lt; prog1.txt &gt;.\r\n\r\nmath &lt; prog1.txt\"<\/pre>\n<p align=\"justify\">You can also list out the Mathematica job submission script via command &#8220;hpc pbs mathematica&#8221; in the HPC system terminal.<\/p>\n<p align=\"justify\">If you code the data results printed on the screen in the notebook program, you can find the data results in the job output file as defined as \u201cstdout.o\u201d (you can change the filename to other names); if you code the data results saved into a file, then you shall find the result file in the folder of where prog1.txt is located.<\/p>\n<p>[\/vc_toggle][vc_toggle title=&#8221;3. How do I clear all of the variables in Mathematica&#8221; style=&#8221;round&#8221; size=&#8221;sm&#8221;]<\/p>\n<p align=\"justify\">To clear any global variables that you\u2019ve created during a Mathematica session, use the following command:<\/p>\n<pre class=\"no-style hpc-codestyling\">ClearAll[\"Global`*\"];<\/pre>\n<p align=\"justify\">To clear all global variables and remove them, do the following command:<\/p>\n<pre class=\"no-style hpc-codestyling\">ClearAll[\"Global`*\"];\r\n Remove[\"Global`*\"];<\/pre>\n<p align=\"justify\">Note that neither of these commands will clear any of the packages that you have loaded; they will also not clear any Mathematica system variables, such as those variables that keep track of your command history.<\/p>\n<p align=\"justify\">If your needs are more extensive, then you will want to use the CleanSlate command. If you have Mathematica 3.0 or later, this command is already available in the CleanSlate package.<\/p>\n<pre class=\"no-style hpc-codestyling\">In[1]:= &lt;&lt;Utilities`CleanSlate`<\/pre>\n<p align=\"justify\">If you load this package at the beginning of your session, you can return your session to its original state with the CleanSlate command.<\/p>\n<pre class=\"no-style hpc-codestyling\">In[2]:= x = 1\r\n Out[2]= 1\r\n \r\n In[3]:= CleanSlate[]\r\n Out[3] = {CleanSlate`, Global`, System`}\r\n \r\n In[4]:= x\r\n Out[4]= x<\/pre>\n<p align=\"justify\">You can add the command to your init.m file to load the CleanSlate everytime you start the kernel.<\/p>\n<p>[\/vc_toggle][vc_toggle title=&#8221;4. How do I write a function which evaluates only when the argument is a number?&#8221; style=&#8221;round&#8221; size=&#8221;sm&#8221;]<\/p>\n<p align=\"justify\">Most kernel functions will return unevaluated when given undefined symbols as arguments, for example<\/p>\n<pre class=\"no-style hpc-codestyling\">In[1]:= Sin[x]\r\n Out[1]= Sin[x]<\/pre>\n<p align=\"justify\">The standard way users write functions does not have this property.<\/p>\n<pre class=\"no-style hpc-codestyling\">In[2]:= f[q_] := q^2\r\n In[3]:= f[x]\r\n Out[3]= x2<\/pre>\n<p align=\"justify\">The way to get f[] to return unevaluated for non-numerical arguments is to write it in a way that is defined only for numerical arguments.<\/p>\n<pre class=\"no-style hpc-codestyling\">In[4]:= Clear[f]\r\n In[5]:= f[q_?NumberQ] := q^2\r\n In[6]:= f[x]\r\n Out[6]= f[x]\r\n In[7]:= f[2.718]\r\n Out[7]= 7.38752<\/pre>\n<p align=\"justify\">The pattern q_?NumberQ will match one of anything, but only if it is a number. In f[x], the x does not meet this criterion, so the f[x] is just echoed as an undefined expression. This technique can be used to limit a function to just matrix arguments, integer arguments, etc, or to use the same function name with different definitions, depending on the type of argument.<\/p>\n<p>[\/vc_toggle][vc_toggle title=&#8221;5. Can Mathematica import MatLab M-files?&#8221; style=&#8221;round&#8221; size=&#8221;sm&#8221;]Mathematica cannot import MatLab .M files. However, it can import Matlab .MAT files. The Mathematica Import[ ] function, when invoked with \u201cMAT\u201d as the third argument, will read Matlab version 4 matrix format. This is a special binary format that is used when you invoke the save() command in MatLab. The Math Works changed over to a proprietary binary format for Matlab version 5. We do not support this format, but it is possible to invoke save() in MatLab version 5 so that it generates the older format instead. You should consult your MatLab documantation on details about how to use save().[\/vc_toggle][\/vc_column][\/vc_row]<\/p>\n<\/section>","protected":false},"excerpt":{"rendered":"<p>[vc_row css=&#8221;.vc_custom_1540890245444{padding-top: 0px !important;padding-bottom: 0px !important;}&#8221;][vc_column][vc_row_inner css=&#8221;.vc_custom_1540890707324{margin-bottom: 60px !important;}&#8221;][vc_column_inner][vc_column_text] FAQ: Mathematica [\/vc_column_text][\/vc_column_inner][\/vc_row_inner][vc_toggle title=&#8221;1. How to start Mathematica&#8221; style=&#8221;round&#8221; size=&#8221;sm&#8221;] Mathematica has two interfaces: command line interface and Graphical User Interface (GUI). To start the command line interface, enter command math and to start the graphics GUI, enter command mathematica GUI Mathematica is supported on MobileVisLab<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_oasis_is_in_workflow":0,"_oasis_original":0,"footnotes":""},"categories":[249],"tags":[],"class_list":["post-12461","post","type-post","status-publish","format-standard","hentry","category-faq-hpc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>FAQ: Mathematica - NUS Information Technology | NUS IT Services, Solutions &amp; Governance<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FAQ: Mathematica - NUS Information Technology | NUS IT Services, Solutions &amp; Governance\" \/>\n<meta property=\"og:description\" content=\"[vc_row css=&#8221;.vc_custom_1540890245444{padding-top: 0px !important;padding-bottom: 0px !important;}&#8221;][vc_column][vc_row_inner css=&#8221;.vc_custom_1540890707324{margin-bottom: 60px !important;}&#8221;][vc_column_inner][vc_column_text] FAQ: Mathematica [\/vc_column_text][\/vc_column_inner][\/vc_row_inner][vc_toggle title=&#8221;1. How to start Mathematica&#8221; style=&#8221;round&#8221; size=&#8221;sm&#8221;] Mathematica has two interfaces: command line interface and Graphical User Interface (GUI). To start the command line interface, enter command math and to start the graphics GUI, enter command mathematica GUI Mathematica is supported on MobileVisLab\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/\" \/>\n<meta property=\"og:site_name\" content=\"NUS Information Technology | NUS IT Services, Solutions &amp; Governance\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-09T08:47:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-07T04:50:04+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/\",\"url\":\"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/\",\"name\":\"FAQ: Mathematica - NUS Information Technology | NUS IT Services, Solutions &amp; Governance\",\"isPartOf\":{\"@id\":\"https:\/\/nusit.nus.edu.sg\/#website\"},\"datePublished\":\"2020-03-09T08:47:00+00:00\",\"dateModified\":\"2021-12-07T04:50:04+00:00\",\"author\":{\"@id\":\"https:\/\/nusit.nus.edu.sg\/#\/schema\/person\/1d48503b1ae5833c749ed5cfc87fda28\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/nusit.nus.edu.sg\/#website\",\"url\":\"https:\/\/nusit.nus.edu.sg\/\",\"name\":\"NUS Information Technology | NUS IT Services, Solutions &amp; Governance\",\"description\":\"Borderless University, powered by Infinite Technology\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/nusit.nus.edu.sg\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/nusit.nus.edu.sg\/#\/schema\/person\/1d48503b1ae5833c749ed5cfc87fda28\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/nusit.nus.edu.sg\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/955212ca4884ab2a06f3f581f8e497c5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/955212ca4884ab2a06f3f581f8e497c5?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/nusit.nus.edu.sg\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"FAQ: Mathematica - NUS Information Technology | NUS IT Services, Solutions &amp; Governance","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/","og_locale":"en_US","og_type":"article","og_title":"FAQ: Mathematica - NUS Information Technology | NUS IT Services, Solutions &amp; Governance","og_description":"[vc_row css=&#8221;.vc_custom_1540890245444{padding-top: 0px !important;padding-bottom: 0px !important;}&#8221;][vc_column][vc_row_inner css=&#8221;.vc_custom_1540890707324{margin-bottom: 60px !important;}&#8221;][vc_column_inner][vc_column_text] FAQ: Mathematica [\/vc_column_text][\/vc_column_inner][\/vc_row_inner][vc_toggle title=&#8221;1. How to start Mathematica&#8221; style=&#8221;round&#8221; size=&#8221;sm&#8221;] Mathematica has two interfaces: command line interface and Graphical User Interface (GUI). To start the command line interface, enter command math and to start the graphics GUI, enter command mathematica GUI Mathematica is supported on MobileVisLab","og_url":"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/","og_site_name":"NUS Information Technology | NUS IT Services, Solutions &amp; Governance","article_published_time":"2020-03-09T08:47:00+00:00","article_modified_time":"2021-12-07T04:50:04+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/","url":"https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/","name":"FAQ: Mathematica - NUS Information Technology | NUS IT Services, Solutions &amp; Governance","isPartOf":{"@id":"https:\/\/nusit.nus.edu.sg\/#website"},"datePublished":"2020-03-09T08:47:00+00:00","dateModified":"2021-12-07T04:50:04+00:00","author":{"@id":"https:\/\/nusit.nus.edu.sg\/#\/schema\/person\/1d48503b1ae5833c749ed5cfc87fda28"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nusit.nus.edu.sg\/support\/faq-hpc\/mathematica-faq\/"]}]},{"@type":"WebSite","@id":"https:\/\/nusit.nus.edu.sg\/#website","url":"https:\/\/nusit.nus.edu.sg\/","name":"NUS Information Technology | NUS IT Services, Solutions &amp; Governance","description":"Borderless University, powered by Infinite Technology","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nusit.nus.edu.sg\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/nusit.nus.edu.sg\/#\/schema\/person\/1d48503b1ae5833c749ed5cfc87fda28","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nusit.nus.edu.sg\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/955212ca4884ab2a06f3f581f8e497c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/955212ca4884ab2a06f3f581f8e497c5?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/nusit.nus.edu.sg\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/posts\/12461"}],"collection":[{"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/comments?post=12461"}],"version-history":[{"count":0,"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/posts\/12461\/revisions"}],"wp:attachment":[{"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/media?parent=12461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/categories?post=12461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nusit.nus.edu.sg\/wp-json\/wp\/v2\/tags?post=12461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}