iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐣

Getting Started with Julia on Windows 11!

に公開
2025/06/06

In this note, we will learn how to install Julia, set up the Jupyter Notebook environment, and use various packages. When setting up a Windows 11 device, please follow the steps below to finish settings such as displaying hidden files and extensions.

https://zenn.dev/ohno/books/356315a0e6437c/viewer/5412fb

From Installation to Launching Julia

Julia can be installed from the Microsoft Store. We live in a great time.

https://www.microsoft.com/store/productId/9NJNWW8PVKMN

  1. Access the link above and click Get in Store app in the top right.
  2. A small window will open. Click Install to proceed. The installation will finish automatically, so click Open at the end.


  3. There will be an installation process only for the first time (it's quick, so you might not notice), and then Julia will launch automatically.

  4. That was "up to the launch." Let's do a Hello, World! while we're at it.

Jupyter Notebook

Many Julia users do almost all of their work on Jupyter Notebook. Let's try using it first.

Installation

  1. Pressing ] on the previous screen switches to pkg mode.

  2. Typing add IJulia in pkg mode installs IJulia.jl. Other packages are installed in the same way with add ~~~, so keep that in mind.

  3. When the installation is finished, press Backspace. This ends pkg mode and returns you to the normal REPL mode.

  4. Enter using IJulia; notebook(detached=true) in the REPL to launch Jupyter Notebook. Only the first time, install Jupyter via Conda, y/n? will be displayed, so type y and press Enter.

  5. The installation will then begin, and Jupyter Notebook will launch automatically.



REPL Remembers Past Commands

Knowing this or not can make a huge difference in work efficiency and growth rate, so I believe it should be taught early on. Close the Julia window by clicking the × button and restart it.

  1. Press the ↑ key in the REPL to display the history of past commands.

  2. Press Enter to launch Jupyter Notebook again.

Hello World! on the Notebook

  1. Navigate to a directory of your choice. Let's use the desktop for this example.
  2. After moving to the directory, click "New" in the top right, select the Julia version, and create a notebook.
  3. A notebook file will be created, and it will automatically open in a new tab. Click "Untitled" in the top left and rename the notebook.
  4. Enter the title of the notebook and press "Rename".
  5. Enter println("Hello World!") in the box displayed in the middle and click the play button ▷ at the top.
  6. Hello World! will be displayed as the output.

How to Use Julia and Notebooks

  1. Try entering the following code into a notebook cell. These x and y are called variables. x = 1 means "assigning 1 to x". Please be careful as it does not mean "equal" as it does in mathematics. In Jupyter Notebook, the value of the last evaluated line is output. In this case, the value of the last x is evaluated.
Assignment
x = 1
y = 2
x = y
  1. Next, let's perform some simple calculations. Since the value of z is evaluated last, 3 will be output. Using just z will produce the same result. If you use println(z), it will be output even in the middle of the code.

Simple calculation
x = 1
y = 2
z = x + y
  1. Trigonometric and exponential functions can be used without any special preparation. Pi can be used as π or pi. π/2 means π divided by 2.
Functions and constants
sin(π/2)
  1. You can also use Markdown and LaTeX notation. While the cell is selected, click the dropdown that says "Code" at the top. There is an option for Markdown, so click that. The left side of the cell will change slightly.

  2. Enter the following content into this cell. Headings are written as # Title with a space after # or ##. You can use formulas like LaTeX by enclosing them in $$. For Markdown notation, please refer to this guide. Then, press the play button ▶ to see it replaced with headings, text, and formulas.

Example of Markdown notation
# Markdown Example

For example, the addition formula is written as follows.

$$
    \sin(\alpha+\beta) = \sin\alpha \cdot \cos\beta + \cos\alpha \cdot \sin\beta
$$
  1. Finally, let's numerically verify the addition theorem. You can also use Greek letters for variables. Not just in Julia, but in computer calculations in general, results calculated through different methods rarely match perfectly down to the last digit, so you don't need to worry about it. If you're really curious, try the same calculation in another programming language.
Verifying the addition theorem
α = 1
β = 2
println( sin(α+β) )
println( sin(α)*cos(β)+cos(α)*sin(β) )

Using Various Packages

Plotting Graphs

  1. In Julia, you can plot functions and arrays using the Plots.jl package. If you want to plot things like CSV files, you need to store them in an array first.
Installation work (required only once)
using Pkg
Pkg.add("Plots")
Declaration (required every time)
using Plots
Execution example
plot(sin)

https://zenn.dev/ohno/articles/3101433fbe9231

Solving Optimization Problems

  1. Optim.jl allows you to solve optimization problems using various methods. We will find the minimum value and minimum point of f(x)=(x+2)^2+1 using the steepest descent method.
Installation work (required only once)
using Pkg
Pkg.add("Optim")
Declaration (required every time)
using Optim
Execution example
f(x) = (x[1] + 2.0)^2 + 1
x0 = [5.0]
optimize(f, x0, method=GradientDescent())

https://zenn.dev/ohno/articles/2a1dc7d609e5bc

Solving Eigenvalue Problems

  1. Using LinearAlgebra.jl, you can easily find the eigenvalues and eigenvectors of a matrix. It's reliable because LAPACK is running behind the scenes. LinearAlgebra.jl is installed by default.
Declaration (required every time)
using LinearAlgebra
Execution example
A = [-4 0 6;
     -3 2 3;
     -3 0 5]
eigen(A)

https://zenn.dev/ohno/articles/cb10dc5b3f5bbc

Using Special Functions

  1. Julia provides packages for using various special functions.
Installation work (required only once)
using Pkg
Pkg.add("SpecialFunctions")
Declaration (required every time)
using SpecialFunctions
Execution example
gamma(1/2)^2

https://zenn.dev/ohno/articles/f352f354e5cf96

Introduction of Other Articles

  1. Various other notes are available, so feel free to study those that interest you.

Ending the Notebook

  1. Let's finish by selecting File > Close and Halt from the top left. If you only close the tab, the kernel will still be running.

The notebook created this time can be downloaded from the link below.
https://gist.github.com/ohno/1291f2b167e665ec4c04886e4cf0e8fd

Discussion