Question

Task 2 (25 points + 4 points for commenting): Write computer code to perform the Fixed.Point method and use your code to find
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code given below is in the function file FixedPoint.m

FixedPoint.m+ function [x, iter,Ea] FixedPoint (g,x0 , tol) %FIXEDPOINT Finds the fixed point of the function g(x) in the app

function [x,iter,Ea] = FixedPoint(g,x0,tol)
%FIXEDPOINT Finds the fixed point of the function g(x) in the appropriate
%interval.
% Input - anonymous function handle -g, x0 - initial guess,tol-Error
% tolerance.
% Output - x - approximate fixed point,iter-no.of iterations,Ea-approximate
% error.
% Initialize iteration counter
iter = 0;
% Set maximum no. of iterations as 100
maxiter = 100;
% Create array of errors
Ea = zeros(1,maxiter);
% First iteration
x = g(x0);
iter = iter+1;
Ea(iter) = abs((x-x0)/x)*100;
while Ea(iter) >= tol && iter <= maxiter
x0 = x;
x = g(x0);
iter = iter+1;
Ea(iter) = abs((x-x0)/x)*100;
end
Ea = Ea(1:iter);
end

The code given below is in the function file ModifiedSecant.m

ModifiedSecant.m+ function [x, iter, Ea] ModifiedSecant (f, delta, xO, tol) MODIFIEDSECANT Calculates the approximate root of

function [x,iter,Ea] = ModifiedSecant(f,delta,x0,tol)
%MODIFIEDSECANT Calculates the approximate root of f(x) using modified
%secant method.
% Input- f- anonymous function handle, delta- perturbation factor,
% x0 - initial guess, tol - Error tolerance
% Output- x - approximate root, iter - no.of iterations, Ea - approx. Error

% Initialize iteration counter
iter = 0;
% Set maximum number of iterations.
maxiter = 100;
% First iteration
x = x0 - delta*x0*f(x0)/(f(x0+delta*x0)-f(x0));
iter = iter+1;
Ea(iter) = abs((x-x0)/x)*100;

while Ea(iter) >= tol && iter <= maxiter
x0 = x;
x = x0 - delta*x0*f(x0)/(f(x0+delta*x0)-f(x0));
iter = iter+1;
Ea(iter) = abs((x-x0)/x)*100;
end
Ea = Ea(1:iter);

end

For the fixed point iteration to find the root of

f(x) = є1-11.

defined the function g(x) as

g(x) = ln 4x, orall x in [2,4]

We note that ) E [2,4 and the derivative is

g (a)

which has an upper bound in the interval (2,4) as

|g'(x)| = rac{1}{|x|}<rac{1}{2} <1, orall xin(2,4)

because 1/x is a decreasing function. Thus the convergence criteria for fixed point iteration are met and we can apply fixed point iteration method to find the fixed point

g(x^*) = x^*, ln 4x^* = x^*

(a) The result of fixed point method is given below

Approximate Error vs Iteration number 0.5 0.49 0.48 0.47 u 0.46 0.45 0.44 0.43 0.42 0.41 0.4 4 6 8 10 12 14 Iteration Number

The ratio of current error to previous error seems to be tending to a limit that is less than 0.5 . This would indicate that the rate of convergence is linear, to say the least.

(b),(c),(d)

The comparison of results between fixed point and modified secant are shown below.

>> f = @ (x) exp (x)-9*x; >> g = @ (x) 10g (4*x); >> [x, iter, Ea] = FixedPoint ( g, 3,0 .001) ; >> [ms , it,Ems] = Modified

As can be seen fixed point iteration takes 14 iterations where as modified secant takes only 9 iterations. The final guess of the root would be approximately 2.1533. The reason modified secant method is faster is it has closer to quadratic rate of convergence whereas fixed point here as we saw has a linear rate of convergence.

Add a comment
Know the answer?
Add Answer to:
Task 2 (25 points + 4 points for commenting): Write computer code to perform the Fixed.Point...
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
  • Task 3 (36 points +4 points for commenting): Write computer code that performs the Simplex Method...

    matlab code Task 3 (36 points +4 points for commenting): Write computer code that performs the Simplex Method of Linear Programming to determine the optimal solution of the following problem statement. A manufacturer makes three types of plastic fixtures. The time in hours required for molding, trimming, and packaging of each fixture is given in the table below. Type Z 1.5 Type X Type Y Total Time Available Process Molding Trimming Packaging Profit per Fixture $11 12000 4600 2400 2/3...

  • Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you...

    Please code in MatLab or Octave Output should match Sample Output in Second Picture Thank you 5. In this problem we will investigate using the Secant Method to approximate a root of a function f(r). The Secant Method is an iterative approach that begins with initial guesses , and r2. Then, for n > 3, the Secant Method generates approximations of a root of f(z) as In-1-In-2 n=En-1-f (x,-1) f(Fn-1)-f(-2) any iteration, the absolute error in the approximation can be...

  • 1. (30 points) Write a MATLAB code to perform the Secant method of root finding. Write...

    1. (30 points) Write a MATLAB code to perform the Secant method of root finding. Write the code to output the table used in class showing the iteration, root estimate r,, function value at the root estimate f(r,), and the approximate error. Show that the code works by using it to re-solve Homework Assignment II Problem 2c. Which asked you to find the positive root of f(r) r,1.0 and 6 10-6, have the code iterate until the approximate error is...

  • 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,...

  • 6.5 Employ the Newton-Raphson method to determine a real root for 4x20.5 using initial guesses of...

    6.5 Employ the Newton-Raphson method to determine a real root for 4x20.5 using initial guesses of (a) 4.52 f(x) 15.5x Pick the best numerical technique, justify your choice and then use that technique to determine the root. Note that it is known that for positive initial guesses, all techniques except fixed-point iteration will eventually converge. Perform iterations until the approximate relative error falls below 2 %. If you use a bracket- ing method, use initial guesses of x 0 and...

  • You are given the following function () 6a +11 6.1 You are to find the roots of this function using the secant method with z 2.5-and zi = 3.5 1.(6 points) Develop a function m-file that calculate...

    You are given the following function () 6a +11 6.1 You are to find the roots of this function using the secant method with z 2.5-and zi = 3.5 1.(6 points) Develop a function m-file that calculates the root of the above function using the secant method. The function should have the following five inputs only. 1. (2 points) The equation or function whose roots need to be found 2.(2 points) Initial guess -1 3. (2 points) Initial guess A4.(2...

  • . (25 points) The recurrence relation for the Newton's Raphson method is a)0.1.2 f(r.) F(z.) The ...

    . (25 points) The recurrence relation for the Newton's Raphson method is a)0.1.2 f(r.) F(z.) The derivative of the function can be approximately evaluated using finite-difference method. Consider the Forward and Centered finite-difference formulas Forward Finite-Difference Centered Finite-Difference 2h It is worthwhile to mention that modified secant method was derived based on the forward finite- difference formula. Develop a MATLAB functions that has the following syntax function [root,fx,ea,iter]-modnetraph (func,x0,h,es,maxit,sethod, varargin) % modnevtraph: root location zeroes of nonlinear equation f (x)...

  • Task 2: (1 Mark) - Scripts Write a MATLAB script which plots the absolute error between...

    Task 2: (1 Mark) - Scripts Write a MATLAB script which plots the absolute error between your mySqrt() function and the built-in sqrt() function for a variety of N values with: N=1:20 • n=323158 err-le-3. Your plot should clearly show that error decreases until "saturating" somewhere below err. Because the algorithm "converges” (increased in accuracy) very quickly the true accuracy will be several orders of magnitude better than the err value. You should use semilogy () instead of plot() to...

  • II. Using Newton’s method, write a MATLAB program to find the fixed point of the following...

    II. Using Newton’s method, write a MATLAB program to find the fixed point of the following function: ?(?) = √? + ?? accurate to at least 8 decimal places. (HINT: finding the fixed point of f(x) is the same as finding the zero of g(x) = f(x) − x. ) The output of this program should display in a single table (i) the solution for the fixed point, (ii) the initial guess, (iii) the number of iterations it took to...

  • 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*...

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