Created
April 22, 2013 20:07
-
-
Save zidarsk8/5438072 to your computer and use it in GitHub Desktop.
regula falsi
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
def regulaFalsi(eps:Double)(from:Double, to:Double, f: Double => Double) : Double = { | |
var i = 1000 | |
var a = from | |
var fa = f(a) | |
var b = to | |
var fb = f(b) | |
var c = a - fa * (b-a)/(fb-fa) | |
var fc = f(c) | |
while (abs(fc)>eps && b-a > eps && {i-=1;i} > 0){ | |
println(a,b,c,fa,fb,fc) | |
if (fa*fc < 0){ | |
b = c | |
fb = fc | |
} else { | |
a = c | |
fa = fc | |
} | |
c = a - fa *(b-a)/(fb-fa) | |
fc = f(c) | |
} | |
c | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about this instead?
DISCLAIMER: I didn't even try to compile this