Last active
August 16, 2020 20:06
-
-
Save leftaroundabout/2a19aea0e8dcb7b63d919406ecdb8c4a to your computer and use it in GitHub Desktop.
ContinAbsvalParametrisation.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cabal-version: >=1.10 | |
-- Initial package description 'contin-absval-parametrisation.cabal' | |
-- generated by 'cabal init'. For further documentation, see | |
-- http://haskell.org/cabal/users-guide/ | |
name: contin-absval-parametrisation | |
version: 0.1.0.0 | |
synopsis: https://math.stackexchange.com/questions/3792238/idea-behind-reparameterization-hiding-a-corner-in-single-variable-calculus/3792259?noredirect=1#comment7813010_3792259 | |
-- description: | |
homepage: https://gist.github.com/leftaroundabout/2a19aea0e8dcb7b63d919406ecdb8c4a | |
-- bug-reports: | |
license: PublicDomain | |
author: Justus Sagemüller | |
maintainer: (@) jsag $ hvl.no | |
category: Math | |
build-type: Simple | |
extra-source-files: CHANGELOG.md | |
executable contin-absval-parametrisation | |
main-is: Main.hs | |
-- other-modules: | |
-- other-extensions: | |
build-depends: base >=4.10 && <4.15, dynamic-plot >=0.4 && <0.5 | |
-- hs-source-dirs: | |
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.Dynamic.Plot.R2 | |
import Data.Semigroup | |
import Control.Monad (join) | |
f, g :: Double -> Double | |
g t = t^2 | |
f t | |
| t<0 = -t^2 | |
| otherwise = t^2 | |
main :: IO () | |
main = do | |
plotWindow | |
[plotLatest | |
$ (plotDelay 1 $ mempty) | |
: [ plotMultiple | |
[ lineSegPlot [(f t,t),(f t,g t),(t, g t)] | |
, lineSegPlot [(t, g t) | t<-post] | |
<> lineSegPlot [(t,-4),(t,4)] | |
, lineSegPlot [(f t, t) | t<-post] | |
<> lineSegPlot [(-6,t),(6,t)] | |
, lineSegPlot [(f t, g t) | t<-pre] | |
] | |
| (pre,post@(t:_))<-join $ cycle | |
[ [splitAt i [-5,1/20-5 .. 5]|i<-[0..190]] | |
, [splitAt i [5,5-1/20 .. -5]|i<-[190,189..0]] ] | |
] | |
, unitAspect, xInterval (-4,4), yInterval (-3,3), dynamicAxes | |
] | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Haskell script shows an animation of the continuous parametrization of the absolute-value function, as discussed in https://math.stackexchange.com/questions/3792238/idea-behind-reparameterization-hiding-a-corner-in-single-variable-calculus/3792259?noredirect=1#comment7813010_3792259
To run the script, you need a GHC setup with either Cabal or Stack (see https://www.haskell.org/ for instructions).
Running with Cabal: put both files in a directory and execute
cabal run
. (It will take a while to install thedynamic-plot
library with all its dependencies.)