Hello friends!!!!!

problem of the day

PYTHON

11/3/20241 min read

'''

Problem

Root of a function f(x) is defined as the value x where f(x) = 0

Consider a quadratic function ,f(x) = x^2 + 3x - 4

Calculate the value of f(x) at the points x = 7,x = -1,x = 1

a) Calculate the value of the function f(x) at x = 2.

b) Calculate the value of the function f(x) at x = 1

'''

#root_1 and root_2 are values of x where f(x) = 0

#let d = determinant of f(x)

f = x**2 + 3*x -4

d = 3**2 - 4*1*(-4)

root_1 = (-3 + (d**0.5)) / 2

root_2 = (-3 - (d**0.5)) / 2

print(f"{root_1},{root_2} are the roots of the equation f(x).")

def f(x) :

return x**2 +3*x - 4

values = {x : f(x) for x in [-1,1,2,7]}

for x,value in values.items():

print(f"f({x}) = {value}")

Output:

1.0,-4.0 are the roots of the equation f(x).

f(-1) = -6

f(1) = 0

f(2) = 6

f(7) = 66