Post Reply 
Bug in MATH ROM of the TI-95
03-09-2023, 06:30 PM (This post was last modified: 03-09-2023 06:54 PM by Thomas Klemm.)
Post: #3
RE: Bug in MATH ROM of the TI-95
Based on the source code of NTN starting at line 683A I wrote these functions in Python:
Code:
from math import exp, hypot

ε = 1e-9

def df(f, x):
    return (
        (f(ε) - f(-ε)) / ε / 2
        if x == 0
        else (f(x * (1 + ε)) - f(x * (1 - ε))) / ε / 2 / x
    )

def ntn(f, x_0, δ, n):
    x = x_0
    for i in range(n):
        fx = f(x)
        dx = fx / df(f, x)
        if hypot(dx, fx) <= δ:
            break
        x -= dx
    else:
        print("#it REACHED")
    return x

def f(x):
    return exp(x) - 3 * x**2

def g(x):
    return x**2 - 5 * x + 6

This is the mapping of the variables to the registers:
  • 0000: \(x\)
  • 0001: \(\varepsilon = 10^{-9}\)
  • 0005: \(x_0\)
  • 0006: \(f(x)\)
  • 0009: \(\delta\)
  • 0010: \(i\)

Examples

\(
\begin{align}
f(x) &= e^x - 3x^2 \\
x &= -0.458962 \\
x &= 0.910008 \\
x &= 3.73308 \\
\end{align}
\)

Code:
ntn(f, -1, 1e-10, 10)

-0.45896226753694863

Code:
ntn(f, 1, 1e-10, 10)

0.9100075724887092

Code:
ntn(f, 4, 1e-10, 10)

3.7330790286328144


\(
\begin{align}
g(x) &= x^2 - 5 x + 6 \\
x &= 2 \\
x &= 3 \\
\end{align}
\)

Code:
ntn(g, 0, 1e-10, 10)

1.9999999999942588

Code:
ntn(g, 4, 1e-10, 10)

3.0000000000000013


To me the implementation in the MATH ROM looks solid.
However, I was able to get nonsensical results if the starting value was close to a critical point where the derivative is 0.

Examples

Code:
ntn(f, 2.833, 1e-10, 5)

#it REACHED
-271.9295080855029

Code:
ntn(g, 2.5, 1e-10, 10)

#it REACHED
-2746.2796055906856


Though I haven't tried it in an emulator, I assume that both the accuracy \(\delta\) and the maximal number of iterations \(n\) have to be stored in registers 0009 and 0010 respectively.
Also if the value in register 0010 is 0, the default value 10 is used instead.

Maybe you can check if the value in register 0009 is not 0?
It should be a fairly small value, like maybe \(10^{-5}\).

But I'm not sure if that helps.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Bug in MATH ROM of the TI-95 - Namir - 03-08-2023, 07:46 PM
RE: Bug in MATH ROM of the TI-95 - Thomas Klemm - 03-09-2023 06:30 PM
RE: Bug in MATH ROM of the TI-95 - Namir - 03-10-2023, 12:16 PM
RE: Bug in MATH ROM of the TI-95 - Namir - 03-10-2023, 02:07 PM



User(s) browsing this thread: 4 Guest(s)