sourcelibs/Polynomials/demos/curve.xtl
1⍝!/usr/bin/env xetal
2⍝# A curve through five points: the polynomial of degree 4 through
3⍝# them (solving with the Matrix library), where it crosses zero, where
4⍝# it turns (the roots of its derivative), and its picture.
5⍝# Run with "just demo Polynomials curve".
6
7ᵖʸ⁼u̲se< "Polynomials"
8ᵐˣ⁼u̲se< "Matrix"
9x ← -2.0 -1.0 0.0 1.0 2.0
10y ← 3.0 -1.0 1.0 -1.0 3.0
11
12⍝ The coefficients c solve V c = y, V the table of the powers of x.
13V ← x '{ a b → a ^ b } t̲able 4.0 3.0 2.0 1.0 0.0
14c ← y ᵐˣs̲olve V
15ᵖʸt̲ext (f̲loat f̲loor 0.5 + c × 1000.0) ÷ 1000.0 ⍝ rounded for reading
16c ᵖʸa̲t x ⍝ it passes through the points
17
18ᵖʸr̲oots c ⍝ where it crosses zero
19ᵖʸr̲oots ᵖʸd̲erivative c ⍝ where it turns
20
21⍝ Its picture: 81 points from -2 to 2.
22t ← -2.0 + (f̲loat o̲ffsets 81) ÷ 20.0
23picture ← ⎕S̲HOW ⎕P̲ATH 2 81 r̲eshape t c̲at c ᵖʸa̲t t