iMPaCT try f#‎ > ‎

plottingDerivatives-1a

for try-f# http://tinyurl.com/impact-fsharp (should open in another window or tab)

open Impact

let redLine(a, b ,m, xlen) = 
    let mutable x = a-xlen
    let mutable xend = a+xlen
    let mutable y = b-xlen*m
    while (x < xend) do
        dot(x,y) red
        x <- x + 0.5
        y <- y + m*0.5
    dot(a,b) black


clear()


//let f(x) = sin(x/30.0) * 100.0
//let f(x) = 100.0/((2.0**(-(x-40.0)/4.0)) + 1.0) - 45.0
let f(x) = (-25.0) + (0.2 *x) + 100.*(2.**(-(((x-100.)/50.)**2.)) - (2.*(2.**(-(((x-100.)/25.)**2.)))))
//let f(x) = 2.0*x-80.0

let fprime(x,h) = (f(x+h) - f(x)) / h
x <- 0.0
while x < 100.0 do
    dot(x,f(x)) pink
    x <- x + 1.0

h <- 3.0
x <- 0.0
while (x < 100.0) do
    dot(x,fprime(x,h)*10.0) red
    m <- fprime(x,h)
    redLine(x,f(x),m,h*2.0)
    dot(x,f(x)) black
    x <- x + h*5.0


Comments