Question

Write functions for the specified root finding methods. Include a comments in each function that notes the inputs and outputs

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB Code:

close all
clear
clc

tol = 1e-6;
fun = @(x) 54*x^6 + 45*x^5 - 102*x^4 - 69*x^3 + 35*x^2 + 16*x - 4;

% Root in the Interval (-1.5, -1)
root_bisect = bisect(fun, -1.5, -1, tol)
root_secant = secant(fun, -1.5, -1, tol)

function xc = bisect(f,a,b,tol)
if sign(f(a)) * sign(f(b)) >= 0
error('f(a)f(b) < 0 not satisfied!')
end
fa = f(a);
fb = f(b);
while (b - a)/2 > tol
c = (a + b)/2;
fc = f(c);
if abs(f(c)) < tol
break
end
if sign(fc) * sign(fa) < 0
b = c; fb = fc;
else
a = c; fa = fc;
end
end
xc = (a + b)/2;
end

function xc = secant(f,a,b,tol)
while true
c = (b*f(a) - a*f(b)) / (f(a) - f(b));
if abs(f(c)) < tol
break
end
if f(a)*f(c) < 0
b = c;
else
a = c;
end
end
xc = c;
end

Output:

root_bisect =
-1.3813
root_secant =
-1.3813

Add a comment
Know the answer?
Add Answer to:
Write functions for the specified root finding methods. Include a comments in each function that ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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.

  • Write a matlab program to implement the secant root finding method in matlab. The function name...

    Write a matlab program to implement the secant root finding method in matlab. The function name should be Secant and it should take the equation as input whoes root has to be found and the two initial values of a and b and maximum tolerable error. Consider the following example: Your code should generate the following: >> secantAssg5(@(x)(x^4+x^2+x+10),2,3,0.0001)    Xn-1      f(Xn-1)      Xn      f(Xn)      Xn+1      f(Xn+1) 2.0000   32.0000    3.0000 103.0000    1.5493   19.7111 ….. ….. ….. Root is x = 0.13952 ans...

  • 1. (30 points) Write a MATLAB code to perform the Secant method of root finding. Write...

    1. (30 points) Write a MATLAB code to perform the Secant method of root finding. Write the code to output the table used in class showing the iteration, root estimate r,, function value at the root estimate f(r,), and the approximate error. Show that the code works by using it to re-solve Homework Assignment II Problem 2c. Which asked you to find the positive root of f(r) r,1.0 and 6 10-6, have the code iterate until the approximate error is...

  • Page 73, as mentioned in the stated question, is provided below 1. Consider a new root-finding...

    Page 73, as mentioned in the stated question, is provided below 1. Consider a new root-finding method for solving f(x) = 0. Successive guesses for the root are generated from the following recurrence formula: Xn+1 = In f(xn) fhen + f(xn)] – F(Xn) (1) Write a user-defined function with the function call: [r, n] = Root fun (f, xl, tol, N) The inputs and outputs are the same as for the user-defined function Newton described on page 73 of Methods....

  • Matlab only What is the function value at the estimated root after one iteration of the...

    Matlab only What is the function value at the estimated root after one iteration of the bisection method for the root finding equation: f(x) = x^3 -x -11 with xl = -4 and xu = 2.5? Select one: a.-0.7500 x O b.-3.2500 o co d. -10.6719 Which of the following statements is false? All open methods for root finding: Select one: a. Is sensitive to the shape of the function X b. Require two initial guesses to begin the algorithm...

  • Write three functions that compute the square root of an argument using three different methods. The...

    Write three functions that compute the square root of an argument using three different methods. The methods are increasingly sophisticated, and increasingly efficient. The square root of a real number is the values such that x . For us, the values will be double precision variables and so may not be perfectly accurate. Also, for us, assume that is in the range 0.0 to 100.0 You program should have a main() that asks the user for x and an accuracy...

  • Write a MATLAB code employing Secant method and for loop to calculate the root for the following function: ?=?6−?−1 Use 7 iterations with initial guesses x0 = 2 and x1 = 1.

    Write a MATLAB code employing Secant method and for loop to calculate the root for the following function: f=x6-x-1Use 7 iterations with initial guesses x0 = 2 and x1 = 1

  • 13. Write a MATLAB program to find all the roots of a given, twice continuously differentiable,...

    13. Write a MATLAB program to find all the roots of a given, twice continuously differentiable, function f e C2la,b]. on the given interval to find out where it Your program should first probe the function f(x) changes sign. (Thus, the program has, in addition to f itself, four other input arguments: a, b, the number nprobe of equidistant values between a and b at which f is probed, and a tolerance tol.) For each subinterval [a,b;] over which the...

  • matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name...

    matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name the function [max_value, max_index] - LASTNAMES matrix max (x), where input argument x is a vector or matrix (not a scalar), and the outputs are the maximum value(s) and indexes of the maximum value(s) of the mput x. Do not use MATLAB functions max() or find(). Use loops and if branches to determine the maximum elements of matrix. Check for correct number and valid...

  • Questions: 1. Write a MATLAB program to find all the roots of a given, twice continuously differe...

    Questions: 1. Write a MATLAB program to find all the roots of a given, twice continuously differentiable, function f E C2[a, b]. Your program should first probe the function f(x) on the given interval to find out where it changes sign. (Thus, the program has, in addition to f itself, four other input arguments: a, b, the number nprobe of equidistant values between a and b at which f is probed, and a tolerance tol.) For each subinterval [ai,b] over...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT