Question

In: Computer Science

Write a program using the following root-finding methods: Mullers Method Use your programs to find approximations...

Write a program using the following root-finding methods: Mullers Method
Use your programs to find approximations to within 10^(-4) to all zeros of the following cubic polynomials.
Use |P_(n+1)-P_n| as a measure of the error in the iteration. Save all of the iterations. What are your conclusions?
(a) f(x) = x^3-5x^2 + 2x

(b) f(x) = x^3-2x^2-5

The program has to be used with MATLAB. I'm still learning how to use the program. I would love some help and tips on solving these methods. Thank you

Solutions

Expert Solution

INPUT endpoints a, b; tolerance TOL; the maximum number of iterations N0 = log2[(b-a)/TOL].
OUTPUT approximate solution p or message of failure.
Step 1 Set i = 1;
FA = f (a).
Step 2 While i ≤ N0 do Steps 3–6.
Step 3 Set p = a + (b − a)/2; (Compute pi)
FP = f ( p).
Step 4 If FP = 0 or (b − a)/2 < TOL then
OUTPUT (p); (Procedure completed successfully.)
STOP.
Step 5 Set i = i + 1.
Step 6 If FA · FP > 0 then set a = p; (Compute ai, bi.)
FA = FP
else set b = p. (FA is unchanged.)
Step 7 OUTPUT (‘Method failed after N0 iterations, N0 =’, N0);
(The procedure was unsuccessful.)
STOP

The actual code for the above question

% Find the root of f(x) using bisection method

f=@(x) x^3 -5*x^2+2*x; % If f(x) is different then we can change it accordingly.

a = 4; % Initially given the first point, It can change if we start with a different inial guess,

b = 5; % Initially given the second point, It can change if we start with different inial guess.

TOL = 10^(-4); % Given error tolerance.

No = log2[(b-a)/ε]; % Calculation of number of iteration required from error bound equation.

if f(a)*f(b)>0

disp('Wrong choice of a and b; please change the value of and b such that f(a)*f(b)<0')

else

For i=1:No %total number of iteration is No.

c=(a+b)/2; %finding the mid point of a and b.

if f(c)*f(b)>0; %checking the sign of f(c) with respect to f(b)

b=c; %if sign of f(b) and f(c) are the same then change the value of endpoint b as c.

else a=c;%if sign of f(b) and f(c) are not the same then change the value of endpoint a as c.

end

end

fprintf('Root of given equation is %f',c)

% so we got the root of our function f(x).

This is a general code, which you can refer to for your reference.

Here key points -

f(x) = x^3-5x^2 + 2x

  1. There is 3 root for the above cubic. It means we have to supply 3 initial pair of guess value, a & b.
  2. The number of iteration is dependent on b-a.

f(x) = x^3-2x^2-5

  1. It has only one real root. It means our bisection method doesn't solve for the imaginary root of the same and we have to provide only one pair of the initial guess.

Related Solutions

Write a program using Newton's method: Use your programs to find approximations to within 10^(-4) to...
Write a program using Newton's method: Use your programs to find approximations to within 10^(-4) to all zeros of the following cubic polynomials. Use |P_(n+1)-P_n| as a measure of the error in the iteration. Save all of the iterations. What are your conclusions? (a) f(x) = x^3-5x^2 + 2x (b) f(x) = x^3-2x^2-5 The program has to be used with MATLAB. I'm still learning how to use the program. I would love some help and tips on solving these methods....
Using the bisection method:     Make a program to use this method using the following three...
Using the bisection method:     Make a program to use this method using the following three functions and use it to find the root of this function f (x) = x * x * x-8. a) A function so that the user between xlower and xupper that meets the value of the function has a different sign and if he does not ask for new values. b) A function to find the root and call it bisection and perform a...
Use Theon's double sequence (Xn and Yn) method to find the first 10 rational approximations to...
Use Theon's double sequence (Xn and Yn) method to find the first 10 rational approximations to square root of 11. You may use a computer program
Use Selections, DO NOT USE ARRAYS AND METHODS. (Find future dates) Write a program that prompts...
Use Selections, DO NOT USE ARRAYS AND METHODS. (Find future dates) Write a program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1, ..., and Saturday is 6). Also prompt the user to enter the number of days after today for a future day and display the future day of the week. ** Can not use java.time.DayOfWeek; SAMPLE RUN #1: java FindFutureDates Enter today's day: 4↵ Enter the number...
• 1. Write a java program using methods to find the information about a account holder...
• 1. Write a java program using methods to find the information about a account holder at bank. d) Perform the functionalities(Deposit, Withdraw and print) until the user selects to stop.
• 1. Write a java program using methods to find the information about a account holder...
• 1. Write a java program using methods to find the information about a account holder at bank. b) Show different functionalities of a bank account (Deposit, Withdrawal, Print)
• 1. Write a java program using methods to find the information about a account holder...
• 1. Write a java program using methods to find the information about a account holder at bank. c) For every transaction make sure make use of his account balance.
Given the function f(x) on the right solve the following root finding questions: a) Find a...
Given the function f(x) on the right solve the following root finding questions: a) Find a positive root (x > 0) of f(x) using the Bisection Method . b) Find a negative root (x < 0) of f(x) using the Bisection Method. c) Find a positive root (x > 0) of f(x) using the False Position Method. d) Find a negative root (x < 0) of f(x) using the False Position Method. Find your initial Bracket via Trial-and-Error. Use |...
To find a positive root for , write a MATLAB script file that uses Bisection method....
To find a positive root for , write a MATLAB script file that uses Bisection method. Choose any initial value that is needed. Use absolute relative approximate error to be less than 0.01. Your code should report the number of iteration and the value of x.
7. Finding Roots Using the Bisection Method Write a function that implements the "bisection method" for...
7. Finding Roots Using the Bisection Method Write a function that implements the "bisection method" for finding the roots of function. The signature of your function should look like def find_root(f,a,b,n): where n is the maximum number of iterations of to search for the root. The code should follow this algorithm: We are given a continuous function f and numbers a and b and with a<b with f(a)<0<f(b). From the intermediate value theorem we know that there exists a c...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT