Since g(x) = x²-x-20 has zeroes at x= -4 and x = 5, we expect zeroes of f(x) = x²-x-20.2 to be in the neighbourhood of -4 and 5. Concentrating on the positive root, we shall assume that it exists somewhere near 5 but definitely on the interval [0.2, 10.2]. Coarse Grid Search Beginning with a course grid, with left endpoints x0 = [0.2, 2.2, 4.2, 6.2, 8.2] and respective right endpoints x1 = [2.2, 4.2, 6.2, 8.2, 10.2], find the sub-interval in which the zero exists. The vector definition of x and x1 produces a vector of subintervals [(0.2, 2.2), (2.2, 4.2), (4.2, 6.2), (6.2, 8.2), (8.2, 10.2)]. The Intermediate Value Theorem will help to locate the zero in one of these subintervals. Set the left endpoint of this sub-interval = a and the right endpoint = b. Fine Search With a tolerance of 10-⁹, use the Regula Falsi method to compute the root of ƒ in [a, b]. The final value of the root must be stored in the variable fnroot, and the total number of steps must be stored in the variable numsteps. The code below is a modification of the bisection method script from the tutorial. User input is required wherever you see red ###. You are permitted multiple incorrect submissions without penalty. Script 1 %% INPUT: Define the tolerance 2 tol = ### 4 epsilon = 10^4; steps = 1; 6 %% found zero if f(c) <= tol %% An arbitrarily large value to begin with %% To keep track of the number of bisections 7 %% INPUT: Define the left endpoints of the coarse grid 8 x0 = ### 9 x1 = x0+2; 10 11 ye f(x0); 12 y1 = f(x1); %% x and x1 set the endpoints of a coarse grid %% for finding a zero. %% evaluate the function at the left endpoints %% evaluate the function at the right endpoints 13 %% INPUT: Compute the term-by-term product of the endpoint values 14 product = ### 15 index find (product<0); 16 a = x0(index); 17 b x1(index); 18 %% product of the endpoint values %% find the position where product < 0 %% define the left and right boundaries for %% the finer grid. 19 fprintf("The Regula-Falsi method will begin on the interval [%.1f, %.1f]\n",a,b); 20 while epsilon > tol 21 %% INPUT: insert the formula for computing c %% This is really |f(c)-0| fprintf("steps = %d, epsilon = %.10f, c = %.10f\n", steps, epsilon,c); %% Enter this if a root is found 22 #### 23 epsilon = abs(f(c)); 24 25 if epsilon <= tol 26 27 %% 28 %% total number of steps in numsteps. fprintf("With a tolerance of %.0e, after %d steps the root = %.10f\n", tol, steps,c); INPUT: store the final value of the root in fnroot and store the 29 % % These should be commands of the form variable = variable, not variable = value. 30 31 else 33 #### #### if f(b)*f(c) < 0 34 %% INPUT: Pay close attention to the if test above and decide where b=c and a=c should go. 35 36 ### else 37 %% INPUT: Pay close attention to the if test above and decide where b=c and a=c should go. 38 39 40 41 end 42 end 43 44 ### end steps steps + 1; function ans = f(x) 46 end ans = x############ 47 48 Save CReset MATLAB Documentation ► Run Script ?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

--- MATLAB work for Root Finding (Regula Falsi Method) ---

--- Please answer the question in the attached image by replacing the ### with matlab script ---

--- Thank you in adavance ---

Since g(x) = x²-x-20 has zeroes at x= -4 and x = 5, we expect zeroes of f(x) = x²-x-20.2 to be in the neighbourhood of -4 and 5.
Concentrating on the positive root, we shall assume that it exists somewhere near 5 but definitely on the interval [0.2, 10.2].
Coarse Grid Search
Beginning with a course grid, with left endpoints x0 = [0.2, 2.2, 4.2, 6.2, 8.2] and respective right endpoints x1 = [2.2, 4.2, 6.2, 8.2, 10.2], find the sub-interval in which the zero
exists. The vector definition of x and x1 produces a vector of subintervals [(0.2, 2.2), (2.2, 4.2), (4.2, 6.2), (6.2, 8.2), (8.2, 10.2)].
The Intermediate Value Theorem will help to locate the zero in one of these subintervals. Set the left endpoint of this sub-interval = a and the right endpoint = b.
Fine Search
With a tolerance of 10-⁹, use the Regula Falsi method to compute the root of ƒ in [a, b]. The final value of the root must be stored in the variable fnroot, and the total number of
steps must be stored in the variable numsteps.
The code below is a modification of the bisection method script from the tutorial.
User input is required wherever you see red ###.
You are permitted multiple incorrect submissions without penalty.
Script
1 %% INPUT: Define the tolerance
2 tol = ###
4 epsilon = 10^4;
steps = 1;
6
%% found zero if f(c) <= tol
%% An arbitrarily large value to begin with
%% To keep track of the number of bisections
7 %% INPUT: Define the left endpoints of the coarse grid
8 x0 = ###
9 x1 = x0+2;
10
11 ye
f(x0);
12 y1 = f(x1);
%% x and x1 set the endpoints of a coarse grid
%% for finding a zero.
%% evaluate the function at the left endpoints
%% evaluate the function at the right endpoints
13 %% INPUT: Compute the term-by-term product of the endpoint values
14 product = ###
15 index find (product<0);
16 a = x0(index);
17 b x1(index);
18
%% product of the endpoint values
%% find the position where product < 0
%% define the left and right boundaries for
%% the finer grid.
19 fprintf("The Regula-Falsi method will begin on the interval [%.1f, %.1f]\n",a,b);
20 while epsilon > tol
21 %% INPUT: insert the formula for computing c
%% This is really |f(c)-0|
fprintf("steps = %d, epsilon = %.10f, c = %.10f\n", steps, epsilon,c);
%% Enter this if a root is found
22
####
23
epsilon = abs(f(c));
24
25
if epsilon <= tol
26
27 %%
28 %%
total number of steps in numsteps.
fprintf("With a tolerance of %.0e, after %d steps the root = %.10f\n", tol, steps,c);
INPUT: store the final value of the root in fnroot and store the
29 % % These should be commands of the form variable = variable, not variable = value.
30
31
else
33
####
####
if f(b)*f(c) < 0
34 %% INPUT: Pay close attention to the if test above and decide where b=c and a=c should go.
35
36
###
else
37 %% INPUT: Pay close attention to the if test above and decide where b=c and a=c should go.
38
39
40
41
end
42 end
43
44
###
end
steps steps + 1;
function ans = f(x)
46 end
ans = x############
47
48
Save
CReset
MATLAB Documentation
► Run Script
?
Transcribed Image Text:Since g(x) = x²-x-20 has zeroes at x= -4 and x = 5, we expect zeroes of f(x) = x²-x-20.2 to be in the neighbourhood of -4 and 5. Concentrating on the positive root, we shall assume that it exists somewhere near 5 but definitely on the interval [0.2, 10.2]. Coarse Grid Search Beginning with a course grid, with left endpoints x0 = [0.2, 2.2, 4.2, 6.2, 8.2] and respective right endpoints x1 = [2.2, 4.2, 6.2, 8.2, 10.2], find the sub-interval in which the zero exists. The vector definition of x and x1 produces a vector of subintervals [(0.2, 2.2), (2.2, 4.2), (4.2, 6.2), (6.2, 8.2), (8.2, 10.2)]. The Intermediate Value Theorem will help to locate the zero in one of these subintervals. Set the left endpoint of this sub-interval = a and the right endpoint = b. Fine Search With a tolerance of 10-⁹, use the Regula Falsi method to compute the root of ƒ in [a, b]. The final value of the root must be stored in the variable fnroot, and the total number of steps must be stored in the variable numsteps. The code below is a modification of the bisection method script from the tutorial. User input is required wherever you see red ###. You are permitted multiple incorrect submissions without penalty. Script 1 %% INPUT: Define the tolerance 2 tol = ### 4 epsilon = 10^4; steps = 1; 6 %% found zero if f(c) <= tol %% An arbitrarily large value to begin with %% To keep track of the number of bisections 7 %% INPUT: Define the left endpoints of the coarse grid 8 x0 = ### 9 x1 = x0+2; 10 11 ye f(x0); 12 y1 = f(x1); %% x and x1 set the endpoints of a coarse grid %% for finding a zero. %% evaluate the function at the left endpoints %% evaluate the function at the right endpoints 13 %% INPUT: Compute the term-by-term product of the endpoint values 14 product = ### 15 index find (product<0); 16 a = x0(index); 17 b x1(index); 18 %% product of the endpoint values %% find the position where product < 0 %% define the left and right boundaries for %% the finer grid. 19 fprintf("The Regula-Falsi method will begin on the interval [%.1f, %.1f]\n",a,b); 20 while epsilon > tol 21 %% INPUT: insert the formula for computing c %% This is really |f(c)-0| fprintf("steps = %d, epsilon = %.10f, c = %.10f\n", steps, epsilon,c); %% Enter this if a root is found 22 #### 23 epsilon = abs(f(c)); 24 25 if epsilon <= tol 26 27 %% 28 %% total number of steps in numsteps. fprintf("With a tolerance of %.0e, after %d steps the root = %.10f\n", tol, steps,c); INPUT: store the final value of the root in fnroot and store the 29 % % These should be commands of the form variable = variable, not variable = value. 30 31 else 33 #### #### if f(b)*f(c) < 0 34 %% INPUT: Pay close attention to the if test above and decide where b=c and a=c should go. 35 36 ### else 37 %% INPUT: Pay close attention to the if test above and decide where b=c and a=c should go. 38 39 40 41 end 42 end 43 44 ### end steps steps + 1; function ans = f(x) 46 end ans = x############ 47 48 Save CReset MATLAB Documentation ► Run Script ?
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education