{"id":13992737,"url":"https://github.com/mitmath/julia-mit","last_synced_at":"2025-04-14T19:47:29.924Z","repository":{"id":10454805,"uuid":"12625415","full_name":"mitmath/julia-mit","owner":"mitmath","description":"Tutorials and information on the Julia language for MIT numerical-computation courses.","archived":false,"fork":false,"pushed_at":"2025-02-05T00:21:08.000Z","size":23913,"stargazers_count":758,"open_issues_count":0,"forks_count":107,"subscribers_count":51,"default_branch":"master","last_synced_at":"2025-04-07T17:03:47.802Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitmath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-09-05T18:29:35.000Z","updated_at":"2025-03-25T16:48:41.000Z","dependencies_parsed_at":"2024-01-18T04:09:18.417Z","dependency_job_id":"1b759160-613f-4372-8c57-0414b72c8ba4","html_url":"https://github.com/mitmath/julia-mit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitmath%2Fjulia-mit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitmath%2Fjulia-mit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitmath%2Fjulia-mit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitmath%2Fjulia-mit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitmath","download_url":"https://codeload.github.com/mitmath/julia-mit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248951149,"owners_count":21188410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-09T14:02:06.766Z","updated_at":"2025-04-14T19:47:29.876Z","avatar_url":"https://github.com/mitmath.png","language":"Jupyter Notebook","funding_links":[],"categories":["Jupyter Notebook"],"sub_categories":[],"readme":"Julia for Numerical Computation in MIT Courses\n==============================================\n\nSeveral MIT courses involving numerical computation, including\n[18.06](https://github.com/mitmath/1806) / [18.C06](http://people.csail.mit.edu/moitra/096.html), [18.065/18.0651](https://github.com/mitmath/18065),\n[18.303](https://github.com/mitmath/18303),\n[18.330](https://github.com/mitmath/18330),\n[18.335/6.7310](https://github.com/mitmath/18335),\n[18.337/6.7320](https://github.com/mitmath/18337),\nand\n[18.338](https://github.com/mitmath/18338),\nare\nbeginning to use [Julia](http://julialang.org/), a fairly new language\nfor technical computing.  This page is intended to supplement the\n[Julia documentation](http://docs.julialang.org/en/latest/) with some\nsimple tutorials on installing and using Julia targeted at MIT\nstudents.  See also our [Julia\ncheatsheet](Julia-cheatsheet.pdf) listing\na few basic commands, and [various Julia tutorials online](https://julialang.org/learning/).\n\nIn particular, we will be using Julia in the [Jupyter](https://jupyter.org/) browser-based\nenviroment (via the [IJulia](https://github.com/JuliaLang/IJulia.jl)\nplug-in), which leverages your web browser and\n to provide a rich environment\ncombining code, graphics, formatted text, and even equations, with\nsophisticated plots via [Matplotlib](http://matplotlib.org/).\n\nYou can also look at the Jupyter notebook from the [fall 2020 tutorial](Tutorial.ipynb), as well as the [tutorial video (MIT only)](https://mit.zoom.us/rec/share/FcA8_JB8vZ-3FmX6_x2qaeRMk0aCOkFl9cMrba1rhQYDDv8TNeatMqTh7eXabBHq.7AQu81CA0eiu2z7g?startTime=1599594382000).\n\n## Why Julia?\n\nJulia is relatively new\nhigh-level free/open-source language for numerical computing in the\nsame spirit, with a rich set of built-in types and libraries for\nworking with linear algebra and other types of computations, with a\nsyntax that is superficially reminiscent of Matlab's.\nBasically, we are using Julia because, unlike Matlab or Python or R, it\n**scales better to real computational problems** — you can write performance-critical\n\"inner loops\" in Julia, whereas similar tasks in other high-level languages\noften require one to drop down to C or similar low-level languages.  (See e.g. [this 6.172 lecture](https://bit.ly/2QUrgB4) on performance in Julia vs. Python.) Because of\nthis, we are using Julia more and more in our own research, and we want to **teach\nusing software tools that we really employ ourselves**.\n\n## Running Julia in the cloud\n\nThe easiest way to get started with Julia is to run it in the cloud on [`mybinder.org`](https://mybinder.org/), which is as easy as clicking this link:\n\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/mitmath/binder-env/main?urlpath=git-pull%3Frepo%3Dhttps%253A%252F%252Fgithub.com%252Fmitmath%252Fjulia-mit%26urlpath%3Dtree%252Fjulia-mit%252F%26branch%3Dmaster)\n\nThat link opens up a [default MIT-math Julia + Python environment](https://github.com/mitmath/binder-env) that we set up, but you can also [easily set up your own environments](https://mybinder.readthedocs.io/en/latest/index.html).   Although the link above gives you access to [our tutorial notebook here](https://nbviewer.jupyter.org/github/mitmath/julia-mit/blob/master/Tutorial.ipynb), you can create alternate links (e.g. for particular MIT courses) using [nbgitpuller](https://jupyterhub.github.io/nbgitpuller/link).\n\n\nThere are two major drawbacks to using the free `mybinder.org` service:\n\n* It's often slow (sometimes an order of magnitude slower than a typical laptop), especially to start up, although it's probably fast enough for simple problems in coursework.\n\n* It has a very short timeout: if you go for a coffee break, your session will probably have stopped running by the time you get back.  Fortunately, [there are save/download buttons](https://discourse.jupyter.org/t/getting-your-notebook-after-your-binder-has-stopped/3268) that still work in a timed-out session, so you can save your work and restore it after restarting the binder session.\n\n* There are at most 100 simultaneous users for a given configuration repository.  (Therefore, if your instructor wants to use mybinder for a course, encourage them to set up their own docker configuration, perhaps by forking [our repo](https://github.com/mitmath/binder-env).)\n\nEventually you'll probably want to install Julia on your own computer to eliminate these frustrations.  Fortunately, this is usually relatively easy:\n\n## Installing Julia and IJulia on your own computer\n\nFirst, [download the latest release of Julia](https://julialang.org/downloads/) and run the installer.\nThen run the Julia application (double-click on\nit, or run `julia` in a terminal); a window with a `julia\u003e` prompt will appear.  At the `julia\u003e` prompt,\ntype a `]` (close square bracket) to get a [Julia package prompt `pkg\u003e`](https://docs.julialang.org/en/v1/stdlib/Pkg/),\nwhere you can type\n\n```jl\n(v1.11) pkg\u003e add IJulia\n```\n\nYou may also want to install these packages, which we tend to\nuse in a lot of the lecture materials:\n```jl\n(v1.11) pkg\u003e add Interact PyPlot Plots\n```\n(You can install other packages later as you need them using the same interface, of course.  Thousands of other packages can be found on [JuliaHub](https://juliahub.com/).)\n\n#### Running Julia through the JupyterLab app\n\nDownload the [jupyterlab-desktop](https://github.com/jupyterlab/jupyterlab-desktop) program, and launch it.   Click the \"Julia\"\nbutton (or choose \"New \u003e Notebook\" from the file menu and select the \"Julia\" kernel):\n\n![JupyterLab desktop](jupyterlab-desktop.png \"JupyterLab-desktop Window\")\n\nYou should now have an interactive Julia notebook, whose usage\nwe describe below.\n\nIf you have **problems printing** or **exporting PDF** from the JupyterLab Desktop (on some systems this fails if you don't have LaTeX installed), a workaround is to *export as HTML* (from *File \u003e Save and Export Notebook As… \u003e HTML*), open the resulting `.html` in your browser (double-click on it) and print to PDF from your browser.\n\n#### Running Julia through Jupyter in your browser\n\nYou can alternatively use Julia itself to install the Jupyter software\nand have it run its interface through your web browser.\n\nSwitch back to the `julia\u003e` prompt by hitting backspace or ctrl-C, and then\nyou can launch the notebook by running\n```jl\njulia\u003e using IJulia\n\njulia\u003e notebook()\n```\nand type \"y\" if you are asked to install Jupyter.   A \"dashboard\" window like this should open in your web browser (at address `localhost:8888`, which you can return to at any time as long as the `notebook()` server is running; I usually keep it running all the time):\n\n![Jupyter dashboard](dashboard.png \"Jupyter Dashboard Window\")\n\nNow, click on the *New* button and select the *Julia* option to start a new \"notebook\".\n\n(You will have to leave this Julia command-line window open in order\nto keep the Jupyter process running.  Alternatively, you can run `notebook(detached=true)` if you want to run the Jupyter server as a background process, at which point you can close the Julia command line, but then if you\never want to restart the Jupyter server you will need to kill it manually.\n\n### Troubleshooting:\n\n* If you ran into a problem with the above steps, after fixing the problem you can type `build` at the `pkg\u003e` prompt to try to rerun the install scripts.\n* If you tried it a while ago, try running `update` at the `pkg\u003e` prompt and try again:\n  this will fetch the latest versions of the Julia packages in case\n  the problem you saw was fixed.  Run `build IJulia` at the `pkg\u003e` prompt if your Julia version may have changed.  If this doesn't work, try just deleting the whole `.julia` directory in your home directory (on Windows, it is called `AppData\\Roaming\\julia\\packages` in your home directory) and re-adding the packages.\n* On MacOS, you need MacOS 10.8 or later.\n* If the notebook opens up, but doesn't respond (the input label is `In[*]` indefinitely), try creating a new Python notebook (not Julia) from the `New` button in the Jupyter dashboard, to see if `1+1` works in Python.  If it is the same problem, then probably you have a [firewall running](https://github.com/ipython/ipython/issues/2499) on your machine (this is common on Windows) and you need to disable the firewall or at least to allow the IP address 127.0.0.1.  (For the [Sophos](https://en.wikipedia.org/wiki/Sophos) endpoint security software, go to \"Configure Anti-Virus and HIPS\", select \"Authorization\" and then \"Websites\", and add 127.0.0.1 to \"Authorized websites\"; finally, restart your computer.)\n\n## Other Julia environments\n\n### Pluto.jl\n\nA different interactive-computing environment for Julia is [Pluto.jl](https://github.com/fonsp/Pluto.jl), which runs in the browser like Jupyter but is **more oriented towards \"live\" interaction** where updating one piece of code *automatically re-runs anything affected* by that change.   Running Julia is as easy as:\n\n```jl\npkg\u003e add Pluto\n\njulia\u003e using Pluto\n\njulia\u003e Pluto.run()\n```\n\n### VSCode\n\nFor writing larger programs, modules, and packages (as opposed to little interactive snippets), you'll want to start putting code into files and modules, and use a more full-featured code-editing environment.  A popular choice is the free/cross-platform [Visual Studio Code (VSCode)](https://code.visualstudio.com/) editor, which has a [Julia VSCode plugin](https://www.julia-vscode.org/) to provide a full-featured integrated development environment (IDE).\n\n### Other Editors\n\nOf course, there is also good support for editing Julia in many other programs, such as [Emacs](https://github.com/JuliaEditorSupport/julia-emacs), [Vim](https://github.com/JuliaEditorSupport/julia-vim), [Atom](https://github.com/JuliaEditorSupport/atom-language-julia), and [so forth](https://github.com/JuliaEditorSupport).\n\n\n## Updating Julia and IJulia\n\nJulia is improving rapidly, so it won't be long before you want to\nupdate to a more recent version.  The same is true of Julia add-on\npackages like PyPlot.  To update the packages only, keeping Julia itself\nthe same, just run:\n```jl\n(v1.11) pkg\u003e update\n```\nat the Julia `pkg\u003e` prompt after typing `]`; you can also run `] update` in IJulia.\n\nIf you download and install a new version of Julia from the Julia web\nsite, you will also probably want to update the packages with\n`update` (in case newer versions of the packages are required\nfor the most recent Julia).  In any case, if you install a new Julia\nbinary (or do anything that changes the location of Julia on your\ncomputer), you *must* update the IJulia installation (to tell IPython\nwhere to find the new Julia) by running `build` at the\nJulia `pkg\u003e` prompt line (not in IJulia).\n\n## Running Julia in the Jupyter Notebook\n\nOnce you have followed the installation steps above, then you\nwill want to open the Jupyter notebook interface.\nAs explained above, you can either launch the standalone\nJupyterLab Desktop app (which you download and install separately),\nor you can install Jupyter via Julia and run it via your web browser.\n\nEither way, a notebook will combine code, computed results, formatted text, and\nimages; for example, you might use one notebook for each problem set.\nThe notebook window that opens will look something like:\n\n![Jupyter notebook](notebook-1.png \"Jupyter empty notebook\")\n\nIn the browser can click the \"Untitled\" at the top to change the name, e.g. to\n\"My first Julia notebook\"; in JupyterLab you click the \"Rename\" option in the \"File\" menu.  You can enter Julia code at the `In[ ]`\nprompt, and hit **shift-return** to execute it and see the results.\nIf you hit **return** *without* the shift key, it will add additional\nlines to a single input cell.  For example, we can [define a variable](http://docs.julialang.org/en/latest/manual/variables/)\n`x` (using the built-in constant `pi` and the built-in function\n`sin`), and then evaluate a polynomial `3x^2 + 2x - 5` in terms of `x`\n(note that, unlike Matlab or Python, we don't have to type `3*x^2` if\nwe don't want to: a number followed by a variable is automatically\ninterpreted as multiplication without having to type `*`):\n\n![Jupyter notebook](notebook-2.png \"Renamed Jupyter notebook with a result\")\n\nThe result that is printed (in `Out[1]`) is the *last* expression from\nthe input cell, i.e. the polynomial.  If you want to see the value of\n`x`, for example, you could simply type `x` at the second `In[ ]` prompt\nand hit shift-return.\n\nSee, for example, the [mathematical operations in the Julia\nmanual](http://docs.julialang.org/en/latest/manual/mathematical-operations/)\nfor many more basic math functions.\n\n## Plotting\n\nThere are several plotting packages available for Julia.  If you\nfollowed the installation instructions, above, you already have one\nfull-featured Matlab-like plotting package installed:\n[PyPlot](https://github.com/stevengj/PyPlot.jl), which is simply a\nwrapper around Python's amazing [Matplotlib](http://matplotlib.org/) library.\n\nTo start using PyPlot to make plots in Julia, first type `using\nPyPlot` at an input prompt and hit shift-enter.  `using` is the Julia\ncommand to load an [external\nmodule](http://docs.julialang.org/en/latest/manual/modules/) (which\nmust usually [be\ninstalled](http://docs.julialang.org/en/latest/manual/packages/)\nfirst, e.g. by the `] add PyPlot` command from the installation\ninstructions above).  The *very first* time you do `using PyPlot`, it will\ntake some time: the module and its dependencies will be\n\"precompiled\" so that in subsequent Julia sessions it will load quickly.\n\nThen, you can type any of the [commands from\nMatplotlib](http://matplotlib.org/api/pyplot_api.html), which includes\nequivalents for most of the Matlab plotting functions.  For example:\n\n![Jupyter notebook](notebook-3.png \"Jupyter notebook with a plot\")\n\n## Printing/exporting Notebooks\n\nCurrently, printing a notebook from the browser's *Print* command \u003ca\nhref=\"https://github.com/ipython/ipython/issues/4196\"\u003ecan be somewhat problematic\u003c/a\u003e.  There are four solutions:\n\n* At the top of the notebook, click on the *File* menu (in the\n  notebook, *not* the browser's global menu bar), and choose **Print\n  Preview**.  This should open up a window/tab that you can print\n  normally.\n\n* For turning in homework, a class may allow you to submit the notebook file\n  (`.ipynb` file) electronically (the graders will handle printing).  You can save a notebook file in a different location by choosing **Download as** from the notebook's *File* menu.\n\n* The highest-quality printed output is produced by IPython's\n  [nbconvert](http://ipython.org/ipython-doc/rel-1.0.0/interactive/nbconvert.html)\n  utility.  For example, if you have a file `mynotebook.ipynb`, you\n  can run `ipython nbconvert mynotebook.ipynb` to convert it to an\n  HTML file that you can open and print in your web browser.  This\n  requires you to install [IPython](http://ipython.org/install.html),\n  [Sphinx](http://sphinx-doc.org/latest/install.html) (which is\n  automatically installed with the Anaconda Python/IPython distribution), and\n  [Pandoc](http://johnmacfarlane.net/pandoc/installing.html) on your\n  computer.\n\n* If you post your notebook in a Dropbox account or in some other\n  web-accessible location, you can paste the URL into the online [nbviewer](http://nbviewer.ipython.org/) to get a printable version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitmath%2Fjulia-mit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitmath%2Fjulia-mit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitmath%2Fjulia-mit/lists"}