Engee documentation
Notebook

Julia, MATLAB and Python: A Comparative Syntax Reference for Scientific Computing

Introduction

Modern engineering and scientific computing are increasingly using several programming languages at once. MATLAB remains popular in mathematical modeling, Python in data analysis and automation, and Julia is actively developing as a high—performance language for scientific computing.

Despite the differences in syntax, most of the basic structures in these languages are very similar: arrays, functions, loops, vectorization, graphs, and working with data. Therefore, when switching between systems, it is important to understand, first of all, syntactic correspondences.

This example is a practical comparison of Julia, MATLAB, and Python syntax in the "operation → implementation in language" format. The comparative format allows you not only to learn a new language faster, but also to better understand the general principles of scientific programming. In many cases, only the form of the record differs, while the computational logic itself remains the same.

Comparison of the basic syntax

Operation

Julia

MATLAB

Python

Comment

% comment

% comment

# comment

Multi-line comment

#= ... =#

%{ ... %}

""" ... """

Assignment

x = 10

x = 10

x = 10

Dynamic typing

x = 1; x = "hi"

x = 1; x = "hi"

x = 1; x = "hi"

Type verification

typeof(x)

class(x)

type(x)

An integer

x = 10

x = int64(10)

x = 10

A floating-point number

x = 1.5

x = 1.5

x = 1.5

A complex number

1 + 2im

1 + 2i

1 + 2j

Infinity

Inf

Inf

float("inf")

NaN

NaN

NaN

float("nan")

Line

s = "Hello"

s = "Hello"

s = "Hello"

String interpolation

"x = $x"

sprintf("x = %d", x)

f"x = {x}"

String concatenation

"a" * "b"

["a" "b"]

"a" + "b"

Repeating a line

"Hеllo"^3

repmat("Hеllo",1,3)

"Hello"*3

Creating an array/vector

[1,2,3]

[1,2,3]

[1,2,3]

The matrix

[1 2; 3 4]

[1 2; 3 4]

np.array([[1,2],[3,4]])

Indexing starts with

1

1

0

Access to the element

A[1,2]

A(1,2)

A[0,1]

The last element

A[end]

A(end)

A[-1]

Cross-section of an array

A[1:3]

A(1:3)

A[0:3]

Logical indexing

A[A .> 0]

A(A > 0)

A[A > 0]

Size of the array

size(A)

size(A)

A.shape

Length of the array

length(A)

length(A)

len(A)

Creating a null array

zeros(3,3)

zeros(3,3)

np.zeros((3,3))

Creating a unit matrix

I(3) / Matrix(I,3,3)

eye(3)

np.eye(3)

Range

1:10

1:10

range(1,11)

Range step

1:2:10

1:2:10

range(1,11,2)

Element-wise multiplication

A .* B

A .* B

A * B

Matrix multiplication

A * B

A * B

A @ B

Piecemeal degree

A .^ 2

A .^ 2

A ** 2

Matrix division

A \ b

A \ b

np.linalg.solve(A,b)

Transposition

A'

A'

A.T

Concatenating arrays horizontally

[A B]

[A B]

np.hstack((A,B))

Concatenating arrays vertically

[A; B]

[A; B]

np.vstack((A,B))

The if condition

if x > 0 ... end

if x > 0 ... end

if x > 0:

The ternary operator

x > 0 ? a : b

ifelse(x>0,a,b)

a if x>0 else b

The for loop

for i in 1:10 ... end

for i in 1:10 ... end

for i in range(10):

The while loop

while x > 0 ... end

while x > 0 ... end

while x > 0:

Cycle interruption

break

break

break

Skipping an iteration

continue

continue

continue

Function (briefly)

f(x)=x^2

f = @(x) x^2

f = lambda x: x**2

Function (normal)

function f(x) ... end

function y=f(x) ... end

def f(x):

Return of the value

return x

return x

return x

Anonymous function

x -> x^2

@(x) x^2

lambda x: x**2

List Generator

[x^2 for x in 1:5]

arrayfun(@(x)x^2,1:5)

[x**2 for x in range(1,6)]

Dictionary

Dict("a"=>1)

containers.Map()

{"a":1}

Plenty

Set([1,2])

unique([...])

set([1,2])

Checking the accessories

x ∈ A

ismember(x,A)

x in A

Exception handling

try ... catch e ... end

try ... catch ... end

try ... except Exception as e:

Error generation

error("msg")

error("msg")

raise Exception("msg")

Structure/Class

struct Point ... end

classdef Point ... end

class Point:

The abstract type

abstract type Shape end

classdef (Abstract)

from abc import ABC

Importing a module

using LinearAlgebra

import pkg.*

import numpy as np

Connecting a file

include("a.jl")

run("a.m")

import module

Documentation of the function

""" doc """

% help text

""" doc """

Macros

@time, @show

missing

missing

Measuring time

@time expr

tic; ...; toc

timeit()

Output to the console

println(x)

disp(x)

print(x)

Formatted output

@printf

fprintf

print(f"...")

Working with the DataFrame

DataFrame(...)

table(...)

pd.DataFrame(...)

Charts

plot()

plot()

matplotlib.pyplot.plot()

A random number

rand()

rand()

random.random() / np.random.rand()

Sorting

sort(A)

sort(A)

sorted(A)

Map function

map(f,A)

arrayfun(f,A)

map(f,A)

Filtering

filter(f,A)

A(mask)

filter(f,A)

Equality check

==

==

==

Identity verification

===

isequal

is

Missing value

missing

missing

None / np.nan

Nothing / null

nothing

[]

None

Conclusion

Julia, MATLAB, and Python do not compete so much as complement each other in modern engineering and scientific tasks. Despite the differences in philosophy and syntax details, most computational constructs between them have direct analogues.

The comparative format helps to learn new tools faster, transfer algorithms between ecosystems, and better understand the general principles of scientific programming. This is especially important in the Engee multi-language environment, where different languages can be used within the same project.