import math
import numpy as np
import matplotlib.pyplot as plt
def func2 (x):
return((2*x**2)-5*x-12)
def false_position(fx, xl, xu, iter_num):
ea_xr = []
for i in range(iter_num):
xr = (xl*fx(xu) - xu*fx(xl)/(fx(u)- fx(xl))
ea_xr.append(xr)
if (fx(xl)*fx(xr) < 0):
xu=xr
else:
xl = xr
return ea_xr
false_position(func2,0,7,20)
def bisect(fc, xl, xu, iternum):
estimates_xr = []
for i in range(iternum):
xr = (xl + xu)/2
estimates_xr.append(xr)
if (fx(xl)*fx(xr)
xu = xr
else:
xl = xr
return estimates_xr
bisect(func2, 0, 7, 20)
def new_raph1(func, dfunc, xinit, ea, imax=20):
iter=0
xold=xinit
roots=[]
errors=[]
while (iter < imax):
xnew= xold- (func(xold)/dfunc(xold))
roots.appends(xnew)
err = (np.abs((xnew - xold)/xnew)) * 100
xold = xnew
errors.append(err)
if (err<ea):
iter += 1
return roots,errors
x,y = new_raph(func2, der2, 0, 0)
print("roots = ", np.round(x,7), ,"\n", ,"errors = ", np.round(y,7))
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}