feq/main.lua

84 lines
2.3 KiB
Lua

--Bespoke script for calculating one-parameter family of real analytic solutions
--to functional equation f'( f( x ) ) = x.
--Idea: suppose f has fixed point 'p',
--apply the chain rule to functional equation
--get values of f's derivatives at p
--get truncated taylor series expansion of f at p
--plot to get some idea about values, convergence.
local RESOLUTION = 1000
local EXTENT = 16
local FaaDiBruno = require( 'fdb' )
local Ansatz = require( 'ansatz' )
local Poly = require( 'interpolant' )
local a = 0.2
local function PlotFunction( f )
local points = {}
for n = 1, RESOLUTION do
points[ 2 * n - 1 ] = EXTENT * n / RESOLUTION
points[ 2 * n ] = f( EXTENT * n / RESOLUTION )
--inverse
--points[ 2 * RESOLUTION + 2 * n ] = points[ 2 * n - 1]
--points[ 2 * RESOLUTION + 2 * n - 1] = points[ 2 * n ]
end
local x, y = love.graphics.getDimensions()
local tf = love.math.newTransform(
x / EXTENT, y,-- / EXTENT,
0, x / EXTENT,
-y / EXTENT)
local dtf = love.math.newTransform( 0, 0, 0, 1, 1 )
--love.graphics.setColor( 1, 1, 1, 0.5 )
love.graphics.setLineWidth( 0.1 )
love.graphics.setLineJoin( "miter" )
love.graphics.setLineStyle( "smooth" )
local draw = love.draw or function() end
love.draw = function()
draw()
love.graphics.push("transform")
love.graphics.translate( 0, y )
love.graphics.scale( x, -y )
love.graphics.scale( 1 / EXTENT, 1 / EXTENT )
--love.graphics.scale( 1.0 / EXTENT, 1.0 / EXTENT )
love.graphics.line( points )
love.graphics.pop()
love.graphics.print( a )
end
end
love.update = function( dt )
if love.keyboard.isScancodeDown("w") then
a = a + 0.05
love.graphics.setColor( a, 0, 0, a )
love.draw = nil
--PlotFunction( FaaDiBruno( a ) )
--PlotFunction( function(x)return x end)
end
if love.keyboard.isScancodeDown("s") then
a = a - 0.05
love.graphics.setColor( 1, 0, 0, 1 )
love.draw = nil
--[[local f = FaaDiBruno(a)
PlotFunction( f.Interpolant )
PlotFunction( f.Derivative )]]
PlotFunction( function(x)return x end)
local f, df = Poly({[0] = 1.5, 1 + a, 2 })
PlotFunction( f )
PlotFunction( df )
end
if love.keyboard.isScancodeDown("q") then EXTENT = EXTENT + 0.5 end
if love.keyboard.isScancodeDown("e") then EXTENT = EXTENT * 0.99 end
end