0% found this document useful (0 votes)
98 views3 pages

Problem 7: Muller's Method

This document describes Muller's method to find the root of a function. It defines the function f(x) and uses Muller's method in a while loop to iteratively calculate values of a, b, and c to get closer to the root. It runs the algorithm with initial values of a=-15, b=-8, c=-2 and prints the results of each iteration until it converges to a solution within the specified tolerance of 0.000075, finding the root to be 10.5188.

Uploaded by

Roseller Sumonod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views3 pages

Problem 7: Muller's Method

This document describes Muller's method to find the root of a function. It defines the function f(x) and uses Muller's method in a while loop to iteratively calculate values of a, b, and c to get closer to the root. It runs the algorithm with initial values of a=-15, b=-8, c=-2 and prints the results of each iteration until it converges to a solution within the specified tolerance of 0.000075, finding the root to be 10.5188.

Uploaded by

Roseller Sumonod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

22/10/2019 Problem7MullerMethod

Problem 7: Muller's Method

localhost:8891/nbconvert/html/Problem7MullerMethod.ipynb?download=false 1/3
22/10/2019 Problem7MullerMethod

In [1]: # Python3 Program to find root of


# a function, f(x) = 0.0043x4 – 0.0016x3 – 0.7472x2 + 1.8249x + 12.6986
import math;

MAX_ITERATIONS = 10000;

# Function to calculate f(x)


def f(x):

return (0.0043*pow(x, 4) - 0.0016*pow(x,3) - 0.7472*x*x + 1.8249*x + 12.69


86);

def Muller(a, b, c):

res = 0;
i = 0;

while (True):

# Calculating various constants


# required to calculate x3
f1 = f(a); f2 = f(b); f3 = f(c);
d1 = f1 - f3;
d2 = f2 - f3;
h1 = a - c;
h2 = b - c;
a0 = f3;
a1 = (((d2 * pow(h1, 2)) -
(d1 * pow(h2, 2))) /
((h1 * h2) * (h1 - h2)));
a2 = (((d1 * h2) - (d2 * h1)) /
((h1 * h2) * (h1 - h2)));
x = ((-2 * a0) / (a1 +
abs(math.sqrt(a1 * a1 - 4 * a0 * a2))));
y = ((-2 * a0) / (a1 -
abs(math.sqrt(a1 * a1 - 4 * a0 * a2))));

# Taking the root which is


# closer to x2
if (x >= y):
res = x + c;
else:
res = y + c;

# checking for resemblance of x3


# with x2 till two decimal places
#m = res * 100;
#n = c * 100;
#m = math.floor(m);
#n = math.floor(n);

if (abs(f(res))<0.000075):
break;

a = b;
b = c;

localhost:8891/nbconvert/html/Problem7MullerMethod.ipynb?download=false 2/3
22/10/2019 Problem7MullerMethod

c = res;

if (i > MAX_ITERATIONS):
print("Root cannot be found using",
"Muller's method");
break;
i += 1;
print('iteration = {}| a = {}| b = {}| c = {}| function, f = {}'.forma
t(i, round(a,4), round(b,4), round(res,4), round(f(res),4)))

if (i <= MAX_ITERATIONS):
print('iteration = {}| c = {}| function,f = {}'.format(i+1, res, f(res
)))
print("The value of the root is",
round(res, 4));

# Driver Code
a = -15;
b = -8;
c = -2;
Muller(a, b, c);
iteration = 1| a = -8| b = -2| c = -2.4635| function, f = 3.8506
iteration = 2| a = -2| b = -2.4635| c = 19.8573| function, f = 410.3471
iteration = 3| a = -2.4635| b = 19.8573| c = -3.405| function, f = -1.5371
iteration = 4| a = 19.8573| b = -3.405| c = -3.1188| function, f = 0.1945
iteration = 5| a = -3.405| b = -3.1188| c = -3.1503| function, f = 0.0078
iteration = 6| a = -3.1188| b = -3.1503| c = 9.686| function, f = -3.3323
iteration = 7| a = -3.1503| b = 9.686| c = 9.1493| function, f = -4.2467
iteration = 8| a = 9.686| b = 9.1493| c = 11.3123| function, f = 5.8243
iteration = 9| a = 9.1493| b = 11.3123| c = 10.491| function, f = -0.1536
iteration = 10| a = 11.3123| b = 10.491| c = 10.5178| function, f = -0.0052
iteration = 11| c = 10.518756854245318| function,f = -3.703213712569209e-06
The value of the root is 10.5188

localhost:8891/nbconvert/html/Problem7MullerMethod.ipynb?download=false 3/3

You might also like