ubuntu2004
Kernel: Python 3 (system-wide)
In [1]:
ADT: need a text cell to explain computation and result below
In [2]:
Out[2]:
[7, mpf('10.904121659428899')]
In [3]:
In [4]:
Out[4]:
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
/tmp/ipykernel_435/872497054.py in <cell line: 7>()
5 f = lambda x: tan(x) - x
6
----> 7 print(iterative_secant(f, -2, 8, 1e-10, None))
/tmp/ipykernel_435/3663236574.py in iterative_secant(f, x1, x2, tol, known_root)
7 while abs(f(r)) > tol:
8 previous_r = r
----> 9 r = secant_line(f, x1, x2)
10 if known_root is not None:
11 previous_error = abs(known_root - previous_r)
/tmp/ipykernel_435/3663236574.py in secant_line(f, x1, x2)
1 def secant_line(f, x1, x2):
----> 2 return x2 - (f(x2)*(x2 - x1))/(f(x2) - f(x1))
3
4 def iterative_secant(f, x1, x2, tol, known_root = None):
5 r = x2
/tmp/ipykernel_435/872497054.py in <lambda>(x)
3 from mpmath import tan
4
----> 5 f = lambda x: tan(x) - x
6
7 print(iterative_secant(f, -2, 8, 1e-10, None))
/usr/local/lib/python3.8/dist-packages/mpmath/ctx_mp_python.py in __sub__(self, other)
/usr/local/lib/python3.8/dist-packages/mpmath/libmp/libmpf.py in mpf_sub(s, t, prec, rnd)
798 """Return the difference of two raw mpfs, s-t. This function is
799 simply a wrapper of mpf_add that changes the sign of t."""
--> 800 return mpf_add(s, t, prec, rnd, 1)
801
802 def mpf_sum(xs, prec=0, rnd=round_fast, absolute=False):
/usr/local/lib/python3.8/dist-packages/mpmath/libmp/libmpf.py in mpf_add(s, t, prec, rnd, _sub)
763 man = -man
764 ssign = 1
--> 765 bc = bitcount(man)
766 return normalize1(ssign, man, sexp, bc, prec or bc, rnd)
767 # Equal exponents; no shifting necessary
KeyboardInterrupt:
In [0]:
In [0]: