Permalink
Browse files

Initial Commit

  • Loading branch information...
1 parent 660806a commit 18f4805f0a795542c3608af280da5ec3ff18400d Adam Savitzky committed Oct 3, 2012
@@ -0,0 +1 @@
+main
@@ -0,0 +1 @@
+println("Hello, World!")
@@ -0,0 +1 @@
+load("hello.jl")
@@ -0,0 +1 @@
+main
View
@@ -0,0 +1,23 @@
+function is_divisible(dividend, divisor)
+ return dividend % divisor == 0
+end
+
+function is_prime(n::Int64)
+ if (is_divisible(n, 2))
+ return false
+ end
+
+ i = 3
+
+ while i < sqrt(n)
+ if (is_divisible(n, i))
+ return false
+ end
+
+ i += 2
+ end
+
+ return true
+end
+
+print(is_prime(10002021))
@@ -0,0 +1 @@
+main
@@ -0,0 +1,9 @@
+function derivative(fn)
+ return x ->begin
+ h = x == 0 ? sqrt(eps(Float64)) : sqrt(eps(Float64)) * x
+ xph = x + h
+ dx = xph - x
+
+ return (fn(xph) - fn(x)) / dx
+ end
+end
@@ -0,0 +1,3 @@
+load("quadratic.jl")
+
+println(quadratic((x) -> 2x^2 + 30x + 9))
@@ -0,0 +1,20 @@
+load("derivative.jl")
+
+function quadratic(f)
+ # Compute the first derivative of f
+ f1 = derivative(f)
+
+ # Get the y intercept (explictly passing a floating point number)
+ c = f(0.0)
+
+ # Get the y intercept of the first derivative
+ b = f1(0.0)
+
+ a = f(1.0) - b - c
+
+ # Our old friend the quadratic formula
+ # Notice how Julia lets you return multiple values
+ # Multiple values should be separated by a comma and
+ # are returned as a tuple
+ return (-b + sqrt(b^2 -4a*c)) / 2a, (-b - sqrt(b^2 -4a*c)) / 2a
+end

0 comments on commit 18f4805

Please sign in to comment.