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....
Write MIPS code for finding the (estimated) square-root of a number N, by using the following...
Write MIPS code for finding the (estimated) square-root of a number N, by using the following pseudo-code: sqrt = N; repeat 10 times { sqrt = (sqrt + N/sqrt)/2; } The number N is entered by the user and the answer is displayed on the screen as (for example): The square root of 121 is 11. Write MIPS code for finding the distance between two points [x1,y1] and [x2,y2]. The formula for the distance is: z = ?(x2 − x1)2...
Using the bisection method, find the root of the following function: f(x)=cos(2x) - x Use the...
Using the bisection method, find the root of the following function: f(x)=cos(2x) - x Use the following initial values: xl=0 and xu=2 NOTE: Perform only 3 iterations.
Use false position method to find the root of ?(?) = −sin(? − 5) + ?...
Use false position method to find the root of ?(?) = −sin(? − 5) + ? with initial guesses of 0.2 and 1. Show up to three iterations and calculate the relative percent error ?? for each iteration possible? Show full details for at least one iteration to get full points. Also, if three significant figure accuracy is required, show if the value after third iteration is acceptable or not.
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...
Find a root of the following equation by using Newton's method in Matlab 9x^4 + 18x^3...
Find a root of the following equation by using Newton's method in Matlab 9x^4 + 18x^3 + 38x^2 - 57x + 14 = 0;
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 |...
• 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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT