-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f255bf4
commit f3c4d69
Showing
4 changed files
with
1,532 additions
and
30 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a,r,n refers implicitly to \rightarrow a,ar,ar^2,\ldots,ar^{n-1}$$ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# g(a,r,n) = geometric_sequence | ||
# refers implicitly to → a,ar,ar²,…, arⁿ⁻¹ | ||
|
||
# state(i,t) = iteration number and current term (i.e. t = arⁱ) | ||
# start = state(0,i) | ||
# next = (i,t) → (i+1, r*t) | ||
# done when i=n | ||
|
||
struct geometric_sequence | ||
a :: Float64 # start | ||
r :: Float64 # ratio | ||
n :: Int # number of terms | ||
end | ||
|
||
struct geometric_sequence_state | ||
i :: Int # iteration number | ||
t :: Float64 # current term | ||
end | ||
|
||
iterate(g::geometric_sequence) = geometric_sequence_state(0,g.a) # start | ||
|
||
# next should return term and state | ||
function iterate(g::geometric_sequence, s::geometric_sequence_state) | ||
s.t, geometric_sequence_state(s.i+1, g.r * s.t ) | ||
end |
Oops, something went wrong.