Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python Root finding code

import mathdef derivative(f, x): h=1e-8 return (f(x+h)-f(x))/hdef solver(f, x0, epsilon, max_iter): xn=x0 for n in range(0,max_iter): y=f(xn) if abs(y)<epsilon: return xn slope=derivative(f,xn) if(slope==0): return None xn=xn-y/slope return Nonedef loop(f, L_bound, R_bound, increment): solutions=[] while L_bound<=R_bound: solution=solver(f, L_bound, 1e-10, 1000) if solution is not None: solution=round(solution,4) if solution not in solutions: solutions.append(solution) L_bound+=increment print(sorted(solutions)) print(“we found “+str(len(solutions))+” solutions!”)equation=””def f(x): try: y=eval(equation) except ZeroDivisionError: y= 1e-10 return yequation=”x**2–9"loop(f,-100,100,0.5)
Comment

PREVIOUS NEXT
Code Example
Python :: plt.axes muktiple plots 
Python :: biodiversity 
Python :: python save base64 temp file 
Python :: payphone lyrics 
Python :: gun in python turtle 
Python :: REMOVE ALL ROWS FROM DATFRAME WGICH HAS DATA OLDER THAN 3 MONTHS PANDAS 
Python :: # https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#specifying-and-constructing-data-types 
Python :: python making player inventory 
Python :: default python structure 
Python :: cv2 warpaffine rotate 
Python :: tusha 
Python :: creating environment variable in python 
Python :: code help 
Python :: pyqt line edit mouse position change 
Python :: alexa in python 
Python :: for c in range python 
Python :: advanced use of tuples in python 
Python :: django edit model without loading from db 
Python :: pandas melt and stack 
Python :: /var/www/html/flag 
Python :: django url with special characters in template 
Python :: install cs50 library python 
Python :: matplotlib add abline 
Python :: Display tail of the DataFrame 
Python :: scrapping components of webpage 
Python :: web parser python 
Python :: python yellow 
Python :: python static typing 
Python :: Sampling data in different ways 
Python :: dictionart 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =