Skip to content

adding smallscale changes to graham implementation, fft, and thomas. #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions chapters/FFT/code/julia/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions chapters/matrix_methods/thomas/thomas.md
Original file line number Diff line number Diff line change
@@ -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[
Expand All @@ -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}
Expand Down