#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 below). Inside the user-defined function, use the built-in Matlab inline function command (see Lecture Part #3 on Blackboard) to define a function (f(x)) corresponding to the difference between the two sides of the above algebraic equation:
f(x)=sqrt(log(x^2+1)) -x^2*sin(e^x)-2
Part c) Determine ALL the roots(or zeros) of the above-defined equation using the BISECTION METHOD (see details below)with a precision better than 10-n, where n is the number provided by the user by searching the roots using the bisection function in the interval [1,3] at interval steps of 0.2.
Part d) A plot displaying the function corresponding to the difference between the two sides of the above-defined algebraic equation. The x-axis MUST be defined in the range [1,3 ]and the plot MUST have 1000 evenly spaced points. Label the x-axis and y-axis and add a title to the plot. Display inside the function plot all the roots determined from the bisection method.
THE BISECTION METHOD: approximates a root of a function (named f(x)) on an interval containing the root. Assume that xL and xR is an interval [xL,xR] where the function has one root. Assume also that function f(x)is continuous in the interval. If the interval is bisected by computing its midpoint, xM,
XM=(XL+XR)/2
then, three possible situations may occur:
1.f(xM)=0, then xM is the root of the function;
2.the root is in the left half of the interval [xL,xM];
3.the root is in the right half of the interval [xM,xR];
f f(xM)≠ 0, then the interval (left half or right half) where the root is located is bisected again. This process is repeated until |f(xM)|<10-n, returning as the root of the function the last calculated xM.
Program Screen Shot:
Sample Output:
Program Code to Copy:
clc,clear,close all
%% part a)
n = 0; % initialize with a value out of range
while n<2 || n>15
n = input('Enter a positive integer between 2 and 15: ');
end
%% PART b)
f = @(x) sqrt(log(x.^2+1)) -x.^2.*sin(exp(x))-2;
%% PART c)
x0 = 1; xend = 3;
tol = 10^-n;
dx = 0.2; % interval of x
% initialize xL and xR
xL = x0;
xR = xL + dx;
roots = [];
while xR <= xend % ensure xR remains in range of x
err = Inf; % initialize precision error a large positive
value
maxIter = 100; %if can't be found in these iterations, it's not a
root
iter = 1;
% bisection method starts
while err > tol && iter <= maxIter
xM = (xL+xR)/2; % compute midpoint
if sign(f(xM)) == sign(f(xL))
xL = xM;
else
xR = xM;
end
err = abs(f(xM)); % compute the precision error
iter = iter + 1;
end
xR = xR + dx; % extend xR to the right and continue searching
if iter <= maxIter % root is found at xM
roots = [roots xM];
% update xL and xR
xL = xM;
xR = xL + dx;
end
end
% display the roots to command window
disp('roots: '),disp(roots)
%% PART d)
x = linspace(x0,xend,1000);
plot(x,f(x)),hold on, plot(roots,f(roots),'o')
legend('f(x)','roots','location','northwest')
xlabel('x'),ylabel('f(x)'),grid on
------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~
#6 Write a Matlab program that finds numerically all the roots (or the zeros) of the...
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...
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...
please show answer in full with explanation, also show matlab 1. Consider the function f(x)2.753 +18r2 21 12 a) Plot the graph of f(x) in MATLAB and find all the roots of the function f(x) graphically. Provide the code and the plot you obtained. b) Compute by hand the first root of the function with the bisection method, on the interval -1; 0) for a stopping criterion of 1% c) How many iterations on the interval -1, 0 are needed...
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...
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...
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 agraph 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 agraph of f(x) and determine proper intervals...
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...
You are given the following function y = x^4 - 12x^3 + 49x^2 - 78x + 40 Plot this function and use graphic methods to initially estimate the roots of this function. Develop an M-file for false-position method based on figure 5.15 in our textbook. Estimate the third root using your program, until epsilon_a is smaller than 0.5% Fill up the following table for one of the roots FIGURE 5.15 Pseudocode for the modified false-position method. FUNCTION ModFalsePos(xl, xu, es,...
in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge when using Function 4.3.1? Is the root obtained the one that is closest to that guess? )xo = 1.5, (b) x0 = 2, (c) x.-3.2, (d) xo = 4, (e) xo = 5, (f) xo = 27. Function 4.3.1 (newton) Newton's method...
Problem 6 Implement a MATLAB function bisection.m of the form bisection (a, b, f, p, t) function [r, h] Beginning of interval [a, b] % b End of interval [a, b] % f function handle y = f(x, p) % p: parameters to pass through to f % t User-provided tolerance for interval width a: At each step j = 1 to n, carefully choose m as in bisection with the geometric (watch out for zeroes!) Replace a, b by...