Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 181
Image: ubuntu2004
Kernel: Python 3 (system-wide)

Your Real Interest

The idea Newton-Raphson method is that in order to make it easier to find the interest we pretend that the equation is a line and then find the root of the line with the hope that the lines crossing is an excellent approximation to the root we actually need.

The Newton iteration is given by π‘₯𝑛+1=π‘₯π‘›βˆ’π‘“(π‘₯)/𝑓′(π‘₯).The most basic version starts with a single-variable function f defined for a real variable x, the function's derivative f ′, and an initial guess x0 for a root of f. If the function satisfies sufficient assumptions and the initial guess is close (0.00001 in this case but usually a small so we get as cloose to r as possible) then x1=x0-f(x0)/f'(x0). The process is repeated as Xn+1= xn-f(Xn)/f'(Xn) until a sufficiently precise value is reached.
We define the function newton that takes on the f=function, df= derivative of function, x= intial guess, n=how many times we are will run the function (more accuurate the more it runs), err = your current approxiation.The loop approximately
import numpy as np def newton(f, df,x,n,err): i=0 while abs(f(x))> err and i<=n: x= x-f(x)/df(x) i +=1 if i > n: return false else: return x
def f(x): return 8.26*x+(1+x)**(-19)-1 def df(x): return 8.26-19*(1+x)**(-20) r = newton(f,df,1,40,0.0001) print (r) print (787.50 * r)
0.12106321628112304 95.33728282138439
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-2-5b6d19fa7902> in <module> ----> 1 Fridge_loan(0.0001) <ipython-input-1-210fc1b4c415> in Fridge_loan(x) 3 R = 95.30 4 n = 19 ----> 5 for i in range(t*n): 6 A = r/x[1-(r/n)**-n] 7 return x NameError: name 't' is not defined