Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
pp:2023:haskell:l08_2 [2023/04/27 13:48] george.vanuta |
pp:2023:haskell:l08_2 [2023/04/27 14:16] (current) george.vanuta |
||
---|---|---|---|
Line 124: | Line 124: | ||
</code> | </code> | ||
- | **8.3.2.** In order to view an **infinite tree**, we need to convert it to a finite **binary tree**. Define the ''sliceTree'', which takes a level ''k'', an **infinite tree** and returns the first ''k'' levels of our tree, in the form of a finite one. | + | **8.3.2.** In order to view an **infinite tree**, we need to convert it to a finite **binary tree**. Define the function ''sliceTree'', which takes a level ''k'', an **infinite tree** and returns the first ''k'' levels of our tree, in the form of a finite one. |
<code haskell> | <code haskell> | ||
Line 146: | Line 146: | ||
**8.3.3.** Define the ''generateTree'' function, which takes a **root** ''k'', a **left generator** function ''leftF'' and a **right generator** function ''rightF''.\\ | **8.3.3.** Define the ''generateTree'' function, which takes a **root** ''k'', a **left generator** function ''leftF'' and a **right generator** function ''rightF''.\\ | ||
- | For example, let's say we have ''k=2'', ''leftF=(+1)'', ''rightF=(*2)''. This should generate a tree where the root is $math[2], the left child is $math[parent + 1]\\ | + | For example, let's say we have ''k=2'', ''leftF=(+1)'', ''rightF=(*2)''. This should generate a tree where the //root// is $math[2], the //left child// is $math[parent + 1]\\ |
- | and the right child is $math[parent * 2]. | + | and the //right child// is $math[parent * 2]. |
<code haskell> | <code haskell> | ||
Line 277: | Line 277: | ||
derivativeApprox :: (Double -> Double) -> Double -> Double | derivativeApprox :: (Double -> Double) -> Double -> Double | ||
- | |||
- | </code> | ||
- | |||
- | ==== The Newton-Raphson Method ==== | ||
- | |||
- | **8.4.8.** | ||
- | |||
- | The method used for approximating the square root is derived from a more general one, named **The Newton-Raphson Method**. | ||
- | |||
- | This is a generic method used for finding the **roots** of a function ($math[x] | $math[f(x) = 0]). | ||
- | |||
- | Considering the following //sequence//: | ||
- | |||
- | $math[x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}] | ||
- | |||
- | and the //limit//: | ||
- | |||
- | $math[\displaystyle \lim_{n \rightarrow \infty} x_n = r\ \Rightarrow \ f(r) = 0] | ||
- | |||
- | write a function which takes another ''function'' and it approximates a root with **tolerance** ''e=0.00001''. Make use of ''build'', ''select'' and ''derivativeApprox''. | ||
- | |||
- | <code haskell> | ||
- | |||
- | rootApprox :: (Double -> Double) -> Double | ||
</code> | </code> |