Sign inSign up

100hellos/octave

By 100hellos

•Updated 4 months ago

"Hello World!" Written in octave

Image
0

4.6K

100hellos/octave repository overview

⁠Hello World! From octave.

Language page⁠ — context, influences, and learning notes on the 100hellos site.

Source on GitHub⁠ (100hellos/octave)

⁠Trying it

docker run --rm --platform="linux/amd64" 100hellos/octave:latest

⁠Modifying it

Read the repo README⁠, or fork the project⁠ and customize it.

For an interactive shell:

docker run --rm --platform="linux/amd64" --entrypoint="" -it 100hellos/octave:latest zsh

⁠Octave - Hello World!

GNU Octave⁠ is a high-level programming language primarily intended for scientific computing and numerical analysis. It is largely compatible with MATLAB, making it an excellent free and open-source alternative for mathematical computations.

⁠About Octave

Octave was originally conceived in 1988 by John W. Eaton as a companion to a graduate-level textbook on chemical reactor design. The name "Octave" is a reference to Octave Levenspiel, a professor of chemical engineering who inspired the project. The language has evolved far beyond its original chemical engineering roots to become a powerful tool for:

  • Linear algebra operations - Matrix operations are first-class citizens
  • Numerical analysis - Solving differential equations, optimization problems
  • Signal processing - Digital filter design, spectral analysis
  • Data visualization - 2D and 3D plotting capabilities
  • Scientific computing - Statistics, machine learning, and more

⁠Language Features

⁠MATLAB Compatibility

Octave aims for compatibility with MATLAB, meaning most MATLAB scripts will run unchanged in Octave. This makes it an excellent choice for:

  • Students learning numerical computing
  • Researchers needing MATLAB functionality without licensing costs
  • Organizations migrating from proprietary to open-source tools
⁠Matrix-Oriented Programming

Like MATLAB, Octave treats matrices as fundamental data types:

# Create a 3x3 matrix
A = [1, 2, 3; 4, 5, 6; 7, 8, 9]

# Matrix multiplication
B = A * A

# Element-wise operations
C = A .* A  # Note the dot notation
⁠Rich Mathematical Functions

Octave includes thousands of built-in functions for mathematical operations:

# Trigonometric functions
sin(pi/2)

# Linear algebra
eig([1, 2; 3, 4])  # Eigenvalues

# Statistics
mean([1, 2, 3, 4, 5])

⁠The Hello World Code

Our implementation is elegantly simple:

#!/usr/bin/env octave

printf("Hello World!\n");
⁠Code Explanation
  • Shebang line: #!/usr/bin/env octave allows the script to be executed directly
  • printf function: Unlike MATLAB's fprintf, Octave's printf is modeled after C's printf
  • Semicolon: Suppresses output in interactive mode (good practice even in scripts)
  • Newline: \n ensures proper line termination

⁠Why This Matters

This simple "Hello World!" demonstrates several important aspects of Octave:

  1. Script execution: Octave can run as a scripting language, not just interactively
  2. C-style functions: Shows Octave's heritage and low-level capabilities
  3. Cross-platform: The same script works on Windows, macOS, and Linux
  4. Text processing: While known for numerical work, Octave handles string operations too

⁠Octave vs. MATLAB

FeatureOctaveMATLAB
CostFreeCommercial license required
SourceOpen sourceProprietary
Syntax95%+ compatibleReference implementation
ToolboxesLimitedExtensive commercial toolboxes
PerformanceGoodOptimized for specific workflows

⁠Beyond Hello World

After running this container, you might want to explore:

  • Matrix operations: Try creating and manipulating matrices
  • Plotting: Octave has excellent plotting capabilities (though GUI is disabled in this container)
  • Numerical methods: Implement algorithms for solving equations
  • Signal processing: Work with digital signals and filters
  • Statistics: Analyze data sets and compute statistical measures

⁠Fun Fact

Octave's development has been remarkably stable and consistent. The project has maintained backward compatibility while continuously adding features, making it one of the most reliable scientific computing platforms available. Its commitment to MATLAB compatibility has made it a bridge between proprietary and open-source scientific computing.

Tag summary

Content type

Image

Digest

sha256:d7451e78a…

Size

181.8 MB

Last updated

4 months ago

docker pull 100hellos/octave