Plotting
This commit is contained in:
commit
099b8440e2
|
@ -0,0 +1,47 @@
|
|||
--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 function PlotFunction( f )
|
||||
|
||||
local RESOLUTION = 1000
|
||||
|
||||
local points = {}
|
||||
for n = 1, RESOLUTION do
|
||||
points[ 2 * n - 1 ] = n / RESOLUTION
|
||||
points[ 2 * n ] = f( n / RESOLUTION )
|
||||
end
|
||||
|
||||
local tf = love.math.newTransform(
|
||||
0, love.graphics.getHeight(),
|
||||
0, love.graphics.getWidth(),
|
||||
-love.graphics.getHeight())
|
||||
|
||||
love.graphics.setColor( 1, 1, 1, 0.5 )
|
||||
love.graphics.setLineWidth( 0.003 )
|
||||
love.graphics.setLineJoin( "miter" )
|
||||
love.graphics.setLineStyle( "smooth" )
|
||||
local draw = love.draw or function() end
|
||||
|
||||
love.draw = function()
|
||||
draw()
|
||||
love.graphics.replaceTransform( tf )
|
||||
love.graphics.line( points )
|
||||
end
|
||||
|
||||
love.update = function( dt )
|
||||
print( love.mouse.getPosition( ) )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
PlotFunction( function( x ) return x * x end )
|
||||
PlotFunction( function( x ) return x * x * x end )
|
||||
PlotFunction( math.sin )
|
||||
PlotFunction( function( x ) return math.exp( x ) - 1 end )
|
Loading…
Reference in New Issue