September 9, 2022 at 5:19 PM
Write C++ or Python program to Find the root which between 0.5 and 1 for this function f(x) = tan(x*x)-x . You can import tan from the math library
No one has been able to solve it for 48 hours so I will post the answer
from math import floor
from math import log
from math import tan
def func(t):
return tan(t*t) -t
def average(x,y):
return (x+y)/2
x = float(input("the left interval num (0.5) :"))
y = float(input("the right interval num (1) :"))
precision = float(input("Donner la precision (0.00000000001 for ex): "))
for k in range(floor(log(y-x)-log(precision)/log(2))):
if(func(x)*func(average(x,y))>0):
x = average(x,y)
if(func(x)*func(average(x,y))<0):
y = average(x,y)
else:
result = average(x,y)
print(f"Alors resultat est = {result} ")
No one has been able to solve it for 48 hours so I will post the answer
from math import floor
from math import log
from math import tan
def func(t):
return tan(t*t) -t
def average(x,y):
return (x+y)/2
x = float(input("the left interval num (0.5) :"))
y = float(input("the right interval num (1) :"))
precision = float(input("Donner la precision (0.00000000001 for ex): "))
for k in range(floor(log(y-x)-log(precision)/log(2))):
if(func(x)*func(average(x,y))>0):
x = average(x,y)
if(func(x)*func(average(x,y))<0):
y = average(x,y)
else:
result = average(x,y)
print(f"Alors resultat est = {result} ")
