diff --git a/chapters/FFT/code/julia/fft.jl b/chapters/FFT/code/julia/fft.jl index 604dfea1c..0481f16ab 100644 --- a/chapters/FFT/code/julia/fft.jl +++ b/chapters/FFT/code/julia/fft.jl @@ -5,7 +5,7 @@ function DFT(x) # We want two vectors here for real space (n) and frequency space (k) n = 0:N-1 k = n' - transform_matrix = exp.(-2im * pi *n *k / N) + transform_matrix = exp.(-2im*pi*n*k/N) return transform_matrix*x end @@ -22,7 +22,6 @@ function cooley_tukey(x) x_even = x[2] end n = 0:N-1 - #n = n' half = div(N,2) factor = exp.(-2im*pi*n/N) return vcat(x_odd + x_even .* factor[1:half], diff --git a/chapters/computational_geometry/gift_wrapping/graham_scan/code/julia/graham.jl b/chapters/computational_geometry/gift_wrapping/graham_scan/code/julia/graham.jl index 3c4e4366e..f08e948a1 100644 --- a/chapters/computational_geometry/gift_wrapping/graham_scan/code/julia/graham.jl +++ b/chapters/computational_geometry/gift_wrapping/graham_scan/code/julia/graham.jl @@ -7,26 +7,6 @@ function dist(point1::Point, point2::Point) return sqrt((point1.x - point2.x)^2 + (point1.y - point2.y)^2) end -function graham_angle(point1::Point, point2::Point, point3::Point) - # Find distances between all points - a = dist(point3, point2) - b = dist(point3, point1) - c = dist(point1, point2) - - ret_angle = acos((b*b - a*a - c*c)/(2*a*c)) - - if(sign(point1.x - point2.x) != sign(point1.x - point3.x)) - ret_angle += 0.5*pi - end - - if (isnan(ret_angle)) - exit(1) - end - - return ret_angle - -end - function ccw(a::Point, b::Point, c::Point) return ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) end @@ -38,7 +18,8 @@ function graham_scan(points::Vector{Point}) sort!(points, by = item -> item.y) # Sort all other points according to angle with that point - other_points = sort(points[2:end], by = item -> graham_angle(Point(points[1].x - 1,points[1].y), points[1], item)) + other_points = sort(points[2:end], by = item -> atan2(item.y - points[1].y, + item.x - points[1].x)) # Place points sorted by angle back into points vector for i in 1:length(other_points) @@ -69,6 +50,7 @@ function graham_scan(points::Vector{Point}) end function main() + # This hull is just a simple test so we know what the output should be points = [Point(2,1.9), Point(1, 1), Point(2, 4), Point(3, 1), Point(2, 0)] hull = graham_scan(points) println(hull) diff --git a/chapters/matrix_methods/thomas/thomas.md b/chapters/matrix_methods/thomas/thomas.md index dcfef6642..90de2a4c5 100644 --- a/chapters/matrix_methods/thomas/thomas.md +++ b/chapters/matrix_methods/thomas/thomas.md @@ -1,9 +1,6 @@ -##### Dependencies -* [Gaussian Elimination](gaussian_elimination.md) - # Thomas Algorithm -As alluded to in the Gaussian Elimination Chapter, the Thomas Algorithm (or TDMA -- Tri-Diagonal Matrix Algorithm) allows for programmers to **massively** cut the computational cost of their code from $$\sim O(n^3) \rightarrow \sim O(n)$$! This is done by exploiting a particular case of Gaussian Elimination, particularly the case where our matrix looks like: +As alluded to in the [Gaussian Elimination chapter](../gaussian_elimination/gaussian_elimination.md), the Thomas Algorithm (or TDMA -- Tri-Diagonal Matrix Algorithm) allows for programmers to **massively** cut the computational cost of their code from $$\sim O(n^3) \rightarrow \sim O(n)$$! This is done by exploiting a particular case of Gaussian Elimination, particularly the case where our matrix looks like: $$ \left[ @@ -19,7 +16,8 @@ $$ By this, I mean that our matrix is *Tri-Diagonal* (excluding the right-hand side of our system of equations, of course!). Now, at first, it might not be obvious how this helps; however, we may divide this array into separate vectors corresponding to $$a$$, $$b$$, $$c$$, and $$d$$ and then solve for $$x$$ with back-substitution, like before. -In particular, we need to find an optimal scale factor for each row and use that. What is the scale factor? Well, it is the diagonal $$-$$ the multiplicative sum of the off-diagonal elements. In the end, we will update $$c$$ and $$d$$ to be$$c'$$ and $$d'$$ like so: +In particular, we need to find an optimal scale factor for each row and use that. What is the scale factor? Well, it is the diagonal $$-$$ the multiplicative sum of the off-diagonal elements. +In the end, we will update $$c$$ and $$d$$ to be $$c'$$ and $$d'$$ like so: $$ \begin{align}