the number of iterations is =
N =
20
cN =
cN =
-0.68232822418213
f(cN) =
fc =
-1.007468813263301e-06
The file falsepos.m is a script file and secant.m and newton.m are function files. To run falsepos.m, type falsepos in MatLab.
Function files are run differently. For secant.m, type [x,flag,ct]=secant(x0,x1,tol,kmax) and type [x,flag,ct]=newton(x0,tol,kmax) for newton.m. Type help filename to see the details about the file. For example, type help newton and the description of this file will be displayed on the screen.
You need to create two MatLab functions: fun.m and fpfun.m to evaluate the function and the derivative function, respectively, for a given x. You have more than one function to use for your project. You may put all needed functions in the file fun.m and their derivatives in fpfun.m. Put the symbol % at the beginning of each function and delete % only for the function you are currently using.
1/x-tan(x)=0, [pi/100, pi/3]
2^x+exp(x)+2*cos(x)-6=0, [1,3]
has a unique solution in the given interval [a,b]. Use three
given MatLab programs
to find an approximation xn of the solution x*
for each equation such that either
|xn-x*|<10(-6)
or |f(xn)|<10(-6) is satisfied.
For each algorithm, report the following results for each equation: