Question

13. Write a MATLAB program to find all the roots of a given, twice continuously differentiable, function f e C2la,b]. on the

Verify your program by finding the two roots (given in Example 3.5) of the function f(x) 2cosh(x/4)-x. starting your search w

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

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE TTHERE TO HELP YOU..ALL THE BEST..

AS FOR GIVEN DATA..

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 which the function changes sign, your program should then find a root as follows. Use either Newton's method or the secant method to find the root, monitoring decrease in lf(xx). If an iterate is reached for which there is no sufficient decrease (e.g., if If(x)I 2 0.5f(x1)1), then revert back to [a,bil, apply three bisection steps and restart the Newton or secant method. The ith root is deemed "found" as x if both hold a. Verify your program by finding the two roots of the function f(x) 2cosh(x/4)-x, starting your search with [a, b]- [0,10] and nprobe b. Find all the roots of the function 10. sin (x) f(x) f(x)-x x=0 in the interval [-10,10] for tol = 10-7

EXPLANATION ::

MATLAB CODE ::-

function x_best_guess = probFun(f,a,b,nprobe)

dx = (b-a)/nprobe;
i=1;
test = a;
f_sign = sign(subs(f,test));
while i<nprobe
test = test+dx;
if(f_sign~=sign(subs(f,test)))
else
break;
end
i=i+1;
end

x_best_guess = test;

end

--------------------------------------------------------------------------------------


%NEWTON-RAPHSON FUNCTION

function root = newtonRaphsonFun(f,xn,tol,a,b)

fp = diff(f);

f_prev = double(subs(f,xn));

while(true)
  
Xn = xn - double(subs(f,xn)/subs(fp,xn));

if abs(Xn-xn)<tol
root = Xn;
break;
end

xn = Xn;

f_iter = double(subs(f,xn));

if abs( f_iter-f_prev)<tol
another_best_guess = threeBisecFun(f,a,b,tol);
xn = another_best_guess;
end

f_prev = f_iter;
end


---------------------------------------------------------------------------------------------------

function best_guess = threeBisecFun(f,a,b,f_tol)
%called by NewtonRaphsonFun at iteration when f absolute tolerance is not met

f_prev = double(subs(f,a));

while(true)
  
m = (a+b)/2;
fm = double(subs(f,m));

if fm<0
a = m;
else
b = m;
end

fm = double(subs(f,m));

if abs(fm-f_prev)<f_tol
break;
end

f_prev = fm;

end

best_guess = m;
end

-----------------------------------------------------------------------


%command

clc
clear

syms x; %symbolic to make differentiation adjustable when f changes instead of hard coding the derivative of f
f = 2*cosh(x/4)-x

nprobe = 10;
tol = 10^-4;
a = 0;
b = 10;

x_best_guess = probFun(f,a,b,nprobe)

root = newtonRaphsonFun(f,x_best_guess,tol,a,b)

I HOPE YOU UNDERSTAND..

PLS RATE THUMBS UP..ITS HELPS ME ALOT..

THANK YOU...!!

Add a comment
Know the answer?
Add Answer to:
13. Write a MATLAB program to find all the roots of a given, twice continuously differentiable,...
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
  • 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...

  • #6 Write a Matlab program that finds numerically all the roots (or the zeros) of the...

    #6 Write a Matlab program that finds numerically all the roots (or the zeros) of the algebraic equation below in the interval 1.0 <=x<=3.0: sqrt(log(x^2+1))=x^2*sin(e^x)+2 Part a) Prompt the user to enter a positive integer number n, defined the range 2<=n<=15, and then verify if the number entered lies within the specifications. Your program must allow the user to reenter the number without the need to rerun the program. Part b) Create a user-defined function for the bisection method(see details...

  • This program has to be written in matlab 2. Write a function to find a root...

    This program has to be written in matlab 2. Write a function to find a root of f(c) using the secant method. Call this routine secant, call the file secant.m; its first line should be function [x,nf] = secant (fname, x0, x1, tol) fname is the name of the m-file which evaluates the function f(x), 20 and 21 are initial approximations to .c", and tol is a stopping tolerance. Your code should return an approximation x = 2X+1 to 3*...

  • Consider the function xtan x -1 defined over all x. Sketch the function to get an idea of the roots 1 find the first couple of roots using bisection to a precision of machine epsilon 2 after straddli...

    Consider the function xtan x -1 defined over all x. Sketch the function to get an idea of the roots 1 find the first couple of roots using bisection to a precision of machine epsilon 2 after straddling a root, find its value using the Newton-Raphson method. 3 after straddling a root, find its value using the secant method 4 after straddling a root, find its value using the false position method. Determine the order of the methods and comment...

  • This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable...

    This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable to transcribe this imageNewton's Method We have already seen the bisection method, which is an iterative root-finding method. The Newton Rhapson method (Newton's method) is another iterative root-finding method. The method is geometrically motivated and uses the derivative to find roots. It has the advantage that it is very fast (generally faster than bisection) and works on problems with double (repeated) roots, where the...

  • 2) (15 points) a) Determine the roots of f(x)=-12 – 21x +18r? - 2,75x' graphically. In...

    2) (15 points) a) Determine the roots of f(x)=-12 – 21x +18r? - 2,75x' graphically. In addition, determine the first root of the function with b) bisection and c) false-position. For (b) and (c), use initial guesses of x, =-land x, = 0, and a stopping criterion of 1%. 3) (25 points) Determine the highest real root of f(x) = 2x – 11,7x² +17,7x-5 a) Graphically, b) Fixed-point iteration method (three iterations, x, = 3) c) Newton-Raphson method (three iterations,...

  • 3. Use the bisection MATLAB program to estimate the roots of the function k(x) = x2...

    3. Use the bisection MATLAB program to estimate the roots of the function k(x) = x2 - 4, where x's range is [-1, 3). Include solutions for this method in the report. 4. Write a MATLAB program that uses the false-position method to estimate the roots of the function k(x) in problem#3. Include your m-file and solutions for this method in the report. In addition, submit your m-file separately.

  • 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. This question concerns finding the roots of the scalar non-linear function f(x) = r2-1-sinx (1...

    1. This question concerns finding the roots of the scalar non-linear function f(x) = r2-1-sinx (1 mark) (b) Apply two iterations of the bisection method to f(x) 0 to find the positive root. (3 marks) (c) Apply two iterations of the Newton-Raphson method to find the positive root. Choose (3 marks) (d) Use the Newton-Raphson method and Matlab to find the positive root to 15 significant (3 marks) (a) Use Matlab to obtain a graph of the function that shows...

  • 3. Write a code to find 3 roots of the function f(x) 2r3-4x2 -22x +24 for the interval I-5, 5] co...

    3. Write a code to find 3 roots of the function f(x) 2r3-4x2 -22x +24 for the interval I-5, 5] considering the following methods a) Bisection Method b) Newton's Method Hint: Plot a graph of f(x) and determine proper intervals and initial guesses for a) and b), respectively. 3. Write a code to find 3 roots of the function f(x) 2x3-4x2 -22x +24 for the interval [-5, 5] considering the following methods a) Bisection Method b) Newton's Method Hint: Plot...

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