On X (Twitter), Juan Carlos aka @jcponcemath posts math content frequently. I saw hist post about the Aizawa attractor, a spherical-shaped attractor made from 6 parameters (a, b, …, f). Three equations generate a trajectory from an initial point.
I plotted the motion trajectories with Lua and pgfplots based on Juan Montijano, Mario Pérez, Luis Rández, and Juan Luis Varona, “Numerical methods with LuaLaTeX”, TUGboat 35:1, 2014, smiliar like Henri Menke applied it to the Lorentz Attractor.
Today, I saw this beautiful spherical-shaped Aizawa (Langford) attractor based on differential equations visualized by @jcponcemath, so I plotted it in LaTeX using Lua for the calculations with the Euler method and TikZ/pgfplots for drawing in the 3D coordinate system. https://t.co/YbfJRv5UsX pic.twitter.com/bsgY9DxHGZ
— LaTeX.org (@TeXgallery) February 5, 2025
% !TEX lualatex
\documentclass{standalone}
\usepackage{pgfplots,luacode}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{colormaps}
\usetikzlibrary{backgrounds}
\begin{luacode*}
-- Differential equation
function f(x,y,z)
local a = 0.95
local b = 0.7
local c = 0.6
local d = 3.5
local e = 0.25
local f = 0.1
return {(z-b)*x-d*y, d*x+(z-b)*y,
c+a*z-z^3/3-(x^2+y^2)*(1+e*z)+f*z*x^3}
end
-- Write PGFplots data as coordinates
function print_Attractor(h,npoints,option)
-- The initial point (x0,y0,z0)
local x0 = 0.0
local y0 = 1.0
local z0 = 0.0
-- Add random number between -0.25 and 0.25
local x = x0 + (math.random()-0.5)/2
local y = y0 + (math.random()-0.5)/2
local z = z0 + (math.random()-0.5)/2
tex.sprint("\\addplot3[".. option .."] coordinates{")
-- dismiss first 100 points to go into the attractor
for i=1, 100 do
m = f(x,y,z)
x = x + h * m[1]
y = y + h * m[2]
z = z + h * m[3]
end
for i=1, npoints do
m = f(x,y,z)
x = x + h * m[1]
y = y + h * m[2]
z = z + h * m[3]
tex.sprint("("..x..","..y..","..z..")")
end
tex.sprint("}")
end
\end{luacode*}
\newcommand\addAttractorPlot[3][]{%
\directlua{print_Attractor(#2,#3,[[#1]])}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[hide axis, axis equal,
zmin = 0, zmax = 1,
show background rectangle,
/tikz/background rectangle/.style = {
left color = black, right color = black!20,
shading angle = 135}]
\foreach \i in {1,...,10}% step h=0.01, 3000 points:
\addAttractorPlot[color of colormap=100*\i]
{0.01}{3000};
\end{axis}
\end{tikzpicture}
\end{document}Also @74WTungsteno is regularly posting visual math content. I noticed the Rössler attractor, a system of three non-linear ordinary differential equations with chaotic dynamics and fractal properties, originally studied by Otto Rössler.
I plotted it with Lua and pgfplots in the very same way.
The strange Rössler attractor plotted with Lua and TikZ in LaTeX: pic.twitter.com/eZTcMywrFk
— LaTeX.org (@TeXgallery) March 1, 2025
% !TEX lualatex
\documentclass{standalone}
\usepackage{pgfplots,luacode}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{colormaps}
\usetikzlibrary{backgrounds}
\begin{luacode*}
-- Differential equation
function f(x,y,z)
local a = 0.2
local b = 0.2
local c = 5.7
return {-y-z, x+a*y, b+z*(x-c)}
end
-- Write PGFplots data as coordinates
function print_Attractor(h,npoints,option)
-- The initial point (x0,y0,z0)
local x0 = 0.0
local y0 = 1.0
local z0 = 0.0
-- Add random number between -0.25 and 0.25
local x = x0 + (math.random()-0.5)/2
local y = y0 + (math.random()-0.5)/2
local z = z0 + (math.random()-0.5)/2
tex.sprint("\\addplot3[".. option .."] coordinates{")
-- dismiss first 100 points to go into the attractor
for i=1, 100 do
m = f(x,y,z)
x = x + h * m[1]
y = y + h * m[2]
z = z + h * m[3]
end
for i=1, npoints do
m = f(x,y,z)
x = x + h * m[1]
y = y + h * m[2]
z = z + h * m[3]
tex.sprint("("..x..","..y..","..z..")")
end
tex.sprint("}")
end
\end{luacode*}
\newcommand\addAttractorPlot[3][]{%
\directlua{print_Attractor(#2,#3,[[#1]])}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[hide axis, axis equal,
zmin = 0, zmax = 18,
show background rectangle,
/tikz/background rectangle/.style = {
left color = black, right color = black!20,
shading angle = 135}]
\foreach \i in {1,...,10}% step h=0.01, 3000 points:
\addAttractorPlot[color of colormap=100*\i]
{0.01}{3000};
\end{axis}
\end{tikzpicture}
\end{document}See also: Original Source by Stefan Kottwitz
Note: The copyright belongs to the blog author and the blog. For the license, please see the linked original source blog.
Leave a Reply
You must be logged in to post a comment.