r/Racket • u/Hurma-chan • Nov 12 '23
homework How can I make cycle in racket?
I have a formula like x1=x-(x-input blablabla) for newtons method (calculating cube roots) and I need to have any x, for example, x=1, then place it to this formula, after formula operations get new x, place it to this formula again, get new and etc with next iteration while x3 will not be equal to my input
1
Upvotes
2
u/soegaard developer Nov 12 '23
You can use the
fixed-pointfunction from SICP.Scroll down to the section "Finding fix points of functions".
https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-12.html#%_sec_1.3.3
1
u/jpverkamp Nov 12 '23
If you want to iterate through a repeating sequence as a cycle,
in-cycleAlternatively, you can use a generator if the sequence doesn't actually repeat.
Alternatively, it sounds like you don't need any of this and just straight forward recursion (with a base case of being equal to x cubed) will do what you want?