code
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
Related questions
Question
100%
make mathlab code

Transcribed Image Text:(Secant Method) The Secant method is a classic method for approximating the roots
of a given function (which does not require access to the derivative of the function). It
produces a sequence of iterates
T1, F2, 13, . . .
by the recurrence relation
In - In-1
In+1 = Xn - f(x„)-
f(In) – f(Tn-1)
for n = 2,... where a, and r2 are a pair of unequal initial guesses. There are many
ways to decide when to stop the iteration, and in this question, you should stop when
|In – In-1| <= TOL
where TOL is a user supplied tolerance.
Notice this stopping criterion is different from the previous problem.
secant Function:
Input variables:
• an anonymous function representing f
• a scalar representing the initial guess r1
• a scalar representing the initial guess x2
• a scalar representing TOL
Output variables:
a vector of all iterates produced until the stopping criterion was reached
(this vector should include x1 and r2 as its first entries)
A possible sample case is:
> x = secant (@(x) sin(x), 2, 3, le-8)
X =
2.0000
3.0000
3.1837
3.1415
3.1416
3.1416
3.1416
Expert Solution

Step 1
Answer:-
%%Matlab code for finding root using secant
clear all
close all
%function for which root have to find
a=2;b=3; tol=10^-8;
[x]=secant(@(x) sin(x),a,b,tol)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Matlab function for Secant Method
function [root]=secant(f,x0,x1,tol)
%f(x1) should be positive
%f(x0) should be negative
k=10; count=0;
root(1)=x0; root(2)=x1;
while k>tol
count=count+1;
xx=double(x1-(f(x1)*((x1-x0)/(f(x1)-f(x0)))));
x0=x1;
x1=xx;
k=abs(x0-x1);
root(count+2)=xx;
if count>=1000
break
end
end
end
%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%
Step by step
Solved in 2 steps with 1 images

Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education