-
-
Save fuomag9/6201d39e14dac9ca42a02fb014ae8117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sympy | |
from sympy import * | |
X = sympy.Symbol('x') | |
#f=parse_expr(str(input("inserisci la tua funzione\n"))) | |
f=sin(X)-X**2 | |
a=float(input("inserisci il minore dell'intervallo\n")) | |
b=float(input("inserisci il maggiore dell'intervallo\n")) | |
calcolabile=True | |
media=0 | |
stringa_risultato="" | |
for x in range(0,int(input("inserisci quante volte vuoi eseguire il codice\n"))): | |
if ((f.subs(X, a)*f.subs(X, b))<0): | |
media=(a+b)/2 | |
print("a: ",a,"b: ",b) | |
else: | |
print("intervallo non valido") | |
break | |
if ((f.subs(X, a)*f.subs(X, media))<0): | |
b=media | |
elif ((f.subs(X, media)*f.subs(X, b))<0): | |
a=media | |
else: | |
calcolabile=False | |
if (calcolabile): | |
for x in range(0,len(a)-1): | |
if str(a)[x]==str(b)[x]: | |
stringa_risultato+=str(a)[x] | |
print("lo zero si trova a x=",stringa_risultato) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment