From 9a33c2b3a724217509433976f682b8328e51b2cf Mon Sep 17 00:00:00 2001 From: wan-may Date: Sun, 8 Oct 2023 13:20:14 -0300 Subject: [PATCH] readme, fixup --- fdb.lua | 2 +- main.lua | 22 +++++++++++++--------- readme.md | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 readme.md diff --git a/fdb.lua b/fdb.lua index 17f1910..2fe6b92 100644 --- a/fdb.lua +++ b/fdb.lua @@ -3,7 +3,7 @@ local ORDER = 100 local binCoefs = {} - +--memoized binonmial coefficient local function Choose( n, k ) if k < 1 then return 1 end if n < 1 then return 0 end diff --git a/main.lua b/main.lua index 25c8b9f..682d106 100644 --- a/main.lua +++ b/main.lua @@ -71,18 +71,25 @@ local function PlotFunction( f, color ) love.graphics.scale( 1 / (plot.X - plot.x), 1/ (plot.Y - plot.y) ) love.graphics.translate( - plot.x, - plot.y ) love.graphics.setLineWidth( 0.003 * (plot.X - plot.x) ) + + love.graphics.setColor( 0.5, 0.5, 0.5, 0.3 ) + love.graphics.line( -10, -10, 10, 10 ) + love.graphics.line( -10, 0, 10, 0 ) + love.graphics.line( 0, -10, 0, 10 ) if color then love.graphics.setColor( color ) end love.graphics.line( plot.inverse and inverse or points ) + love.graphics.circle( "fill", a, a, 0.003 * (plot.X - plot.x) ) love.graphics.pop() + + love.graphics.setFont( love.graphics.getFont( 48 ) ) love.graphics.print( a ) love.graphics.print( plot.fdbOrder, 0, 15 ) love.graphics.print( f(a), 0, 30 ) love.graphics.print( f(-1.0), 0, 45 ) love.graphics.setColor( 1,1,1,1 ) - love.graphics.setFont( love.graphics.getFont( 48 ) ) end end @@ -92,7 +99,7 @@ love.wheelmoved = function( x, y ) end love.mousepressed = function(x, y, button) - --plot.inverse = not( plot.inverse ) + plot.inverse = not( plot.inverse ) plot.fdbOrder = plot.fdbOrder + (( button == 1 ) and 1 or -1 ) return love.keypressed() end @@ -116,18 +123,15 @@ love.keypressed = function( key, code ) love.draw = nil local f, df, fn = Poly( FaaDiBruno( a, plot.fdbOrder ) ) - --PlotFunction( f, {1, 0, 0, 0.3} ) --Function in red. - --PlotFunction( df, {0, 1, 0, 0.3} ) --First derivative in green. - --local lowF, lowDF = Poly( FaaDiBruno( a, 15 ) ) - --PlotFunction( lowF, {1, 0, 0, 0.3} ) --Function in red. - --PlotFunction( lowDF, {0, 1, 0, 0.3} ) --First derivative in green. + PlotFunction( f, {1, 0, 0, 0.7} ) --Function in red. + PlotFunction( df, {0, 1, 0, 0.7} ) --First derivative in green. --PlotFunction( function(x) return df( f ( x ) ) end, {0, 0, 1, 0.3}) --PlotFunction( function(x) return f( df ( x ) ) end, {1, 1, 1, 0.3}) --PlotFunction( function(x) return x end, {1, 1, 1, 0.3}) local af, an = Poly( Ansatz.coefs ) - PlotFunction( af, {1,1,1, 0.3} ) - PlotFunction( an, {1,1,1, 0.3} ) + --PlotFunction( af, {1,1,1, 0.3} ) + --PlotFunction( an, {1,1,1, 0.3} ) PlotFunction( Ansatz.dpo, {1, 1, 1, 0.3} ) PlotFunction( Ansatz.pos, {1,1,1,0.3} ) end diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..0fb7de2 --- /dev/null +++ b/readme.md @@ -0,0 +1,23 @@ +Bespoke script for calculating and plotting some series solutions +of the 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 series to get some idea about values, convergence. + +We use Faa Di Bruno's formula for iterated derivatives, in terms of Bell numbers. +We also plot the "ansatz" solution, i.e. the solution of the form x -> a * x ^ b where a and b are positive. + +Uses LOVE as a dependency for its plotting: https://love2d.org +Solution is plotted in red, first derivative is plotted in green. + +Keys: +Q - Increase p +E - Decrease p +WASD - Translate view +Z - Zoom in +C - Zoom out +F - Increase order of series expansion +R - Decrease order