Examples

Sample XDL code and tutorials.

For the complete examples documentation, see the Example Gallery.

XDL Examples

Hello World

; Basic introduction to XDL
print, 'Hello, XDL!'

x = 42
print, 'The answer is:', x

; Arithmetic
y = x * 2 + 10
print, 'Calculation:', y

Arrays and Loops

; Create array
arr = findgen(10)
print, 'Array:', arr

; Loop through array
for i = 0, 9 do begin
  arr[i] = arr[i] * 2
  print, 'Element', i, ':', arr[i]
endfor

Trigonometry

; Trigonometric functions
x = findgen(100) * !pi / 50
y_sin = sin(x)
y_cos = cos(x)
y_tan = tan(x)

; Plot results
plot, x, y_sin, title='Sine Wave'
oplot, x, y_cos, color='red'

Conditionals

; If/Then/Else
x = 42

if x gt 50 then begin
  print, 'x is greater than 50'
endif else begin
  print, 'x is less than or equal to 50'
endelse

MATLAB Examples

XDL can run MATLAB code:

Simple Math

% MATLAB code running in XDL
x = 10;
y = 20;
z = x + y;
fprintf('Result: %d\n', z);

Matrix Operations

% Matrix operations
A = [1, 2; 3, 4];
B = [5, 6; 7, 8];
C = A * B;
disp(C);

Scientific Examples

Rayleigh-Taylor Simulation

See Rayleigh-Taylor Demo for a complete physics simulation example.

Bezier Curves

See Bezier Demo for curve drawing examples.

GPU Computation

See GPU Demo for GPU-accelerated examples.

Running Examples

# Run XDL file
xdl examples/xdl/01_hello_world.xdl

# Run MATLAB file (auto-transpiled)
xdl examples/matlab/01_simple_math.m

# Interactive REPL
xdl

Next Steps