aboutsummaryrefslogtreecommitdiff
path: root/Semestr 3/anm/horner.jl
diff options
context:
space:
mode:
Diffstat (limited to 'Semestr 3/anm/horner.jl')
-rw-r--r--Semestr 3/anm/horner.jl16
1 files changed, 16 insertions, 0 deletions
diff --git a/Semestr 3/anm/horner.jl b/Semestr 3/anm/horner.jl
new file mode 100644
index 0000000..a3fb69b
--- /dev/null
+++ b/Semestr 3/anm/horner.jl
@@ -0,0 +1,16 @@
+function horner(w, n, x0)
+ p = w[n + 1]
+ q = 0
+ r = w[n + 1]
+ t = 0
+ for i in range(n, 1, step=-1)
+ q = p + x0 * q
+ p = w[i] + x0 * p
+ t = r + x0 * t
+ r = p + x0 * r
+ end
+ return [p, q, r, t]
+end
+
+
+println(horner([-13, 10, -7, 2], 3, 2)) \ No newline at end of file