Question

In: Computer Science

Using Python, write a program that finds a root of function f(x) = x^2-4x+3 on interval...

Using Python, write a program that finds a root of function f(x) = x^2-4x+3 on interval [2,5] using bisection search method. Recall that r is a root of a function if f(r) = 0. Output the number of iterations it took your algorithm to find a root.

Solutions

Expert Solution

def f(n):
return (n*n)-(4*n)+3
def bisection_method(a,b):
count = 0
if(f(a)*f(b)>=0):
print("Wrong intervals")
return
while((b-a)>0.01):
#count for no of iterations
count+=1
#taking c as middle point of the intervals
c=(b+a)/2
if(f(c)==0):
print("No.of Iternations:",count)
return c
if(f(a)*f(c)<0):
b=c
else:
a=c
print("No.of Iternations:",count)
return c
if __name__=="__main__":
a=2
b=5
print("Root is",bisection_method(a,b))



Related Solutions

Write a program to compute the root of the function f(x) = x3 + 2 x2...
Write a program to compute the root of the function f(x) = x3 + 2 x2 + 10 x - 20 by Newton method ( x0 =2 ). Stop computation when the successive values differ by not more than 0.5 * 10-5 . Evaluate f(x) and f '(x) using nested multiplication. The output should contain: (1) A table showing at each step the value of the root , the value of the function,and the error based upon successive approximation values...
Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2...
Write a Matlab function for: 1. Root Finding: Calculate the root of the equation f(x)=x^3 −5x^2 +3x−7 Calculate the accuracy of the solution to 1 × 10−10. Find the number of iterations required to achieve this accuracy. Compute the root of the equation with the bisection method. Your program should output the following lines: • Bisection Method: Method converged to root X after Y iterations with a relative error of Z.
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2,...
Using Matlab, consider the function f(x) = x^3 – 2x + 4 on the interval [-2, 2] with h = 0.25. Write the MATLAB function file to find the first derivatives in the entire interval by all three methods i.e., forward, backward, and centered finite difference approximations. Could you please add the copiable Matlab code and the associated screenshots? Thank you!
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2...
Use the secant Method to find a root for the function: f(x) = x^3 + 2x^2 + 10x -20, with x_0 = 2, and x_1 = 1.
Consider the root of function f(x) = x 3 − 2x − 5. The function can...
Consider the root of function f(x) = x 3 − 2x − 5. The function can be rearranged in the form x = g(x) in the following three ways: (a) x = g(x) = x3 − x − 5 (b) x = g(x) = (x 3 − 5)/2 (c) x = g(x) = thirdroot(2x + 5) For each form, apply fixed-point method with an initial guess x0 = 0.5 to approximate the root. Use the error tolerance = 10-5 to...
Q.3 Consider the function f(x) = x^2– 2x + 4 on the interval [-2, 2] with...
Q.3 Consider the function f(x) = x^2– 2x + 4 on the interval [-2, 2] with h = 0.25. Write the MATLAB function file to find the first derivatives in the entire interval by all three methods i.e., forward, backward, and centered finite difference approximations.
Consider the function f(x) = x 4 − 4x 2 . Determine the following: • The...
Consider the function f(x) = x 4 − 4x 2 . Determine the following: • The (x,y) coordinate pairs of the local minima and local maxima. • The (x,y) coordinate pair of the absolute minimum and absolute maximum, should they exist. If the absolute min/max is obtained at multiple points, list all of them. • The intervals of increasing and decreasing. • The intervals of concavity. That is, explain exactly where this function is convex and exactly where this function...
For the function f(x)=x^4-3x^3+x^2+4x+21 Use long division to determine whether x+3 is a factor of f(x)....
For the function f(x)=x^4-3x^3+x^2+4x+21 Use long division to determine whether x+3 is a factor of f(x). Is x+3 a factor of f(x)?
Using Python write a function that implements the following two-dimensional objective function: F (x, y) =...
Using Python write a function that implements the following two-dimensional objective function: F (x, y) = (x^2 + y − 11)^2 + (x + y^2 − 7 )^22 . Determine how many local minimums and maximums and their location for this objective function.
Using extended euclidean algorithm find f(x) and g(x) in: f(x)(x^5 + 4x^4 + 6x^3 + x^2...
Using extended euclidean algorithm find f(x) and g(x) in: f(x)(x^5 + 4x^4 + 6x^3 + x^2 + 4x + 6) + g(x)(x^5 + 5x^4 + 10x^3 + x^2 + 5x + 10) = x^3+1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT