Question

In: Advanced Math

Finally, consider the following fixed point iteration xk+1 = g(xk) = arccos −1 1 + e...

Finally, consider the following fixed point iteration xk+1 = g(xk) = arccos −1 1 + e 2x and show that finding a fixed point of g(x) is equivalent to finding a root of f(x) = 0. Use the code fixedpt.m to try to approximate the root using an initial guess of x0 = −3. Can you explain why your iteration behaves as it does? Hint: Plot the fixed-point function and think convergence!

Code in fixedpt.m:-

function [xfinal, niter, xlist] = fixedpt( gfunc, xguess, tol )
% FIXEDPT: Fixed point iteration for x=gfunc(x).
%
%  Sample usage:
%     [xfinal, niter, xlist] = fixedpt( gfunc, xguess, tol )
%
%  Input:
%     gfunc   - fixed point function 
%     xguess  - initial guess at the fixed point
%     tol     - convergence tolerance (OPTIONAL, defaults to 1e-6)
%
%  Output:
%     xfinal  - final estimate of the fixed point
%     niter   - number of iterations to convergence
%     xlist   - list of interates, an array of length 'niter'

% First, do some error checking on parameters.
if nargin < 2
  fprintf( 1, 'FIXEDPT: must be called with at least two arguments' );
  error( 'Usage:  [xfinal, niter, xlist] = fixedpt( gfunc, xguess, [tol] )' );
end
if nargin < 3, tol = 1e-6; end

% fcnchk(...) allows a string function to be sent as a parameter, and
% coverts it to the correct type to allow evaluation by feval().
gfunc = fcnchk(gfunc);
x = xguess;
xlist = [ x ];

niter = 0;
done  = 0;
while ~done,
  xnew  = feval(gfunc,  x);
  xlist = [ xlist; xnew ];  % create a list of x-values 
  niter = niter + 1;
  if abs(x-xnew) < tol,     % stopping tolerance for x only
    done = 1;
  end
  x = xnew;
end
xfinal = xnew;

Solutions

Expert Solution

clc
clear all
close all
format long;
g=@(x) acos(-1./(1+exp(2*x)));
[xfinal, niter, xlist] = fixedpt( g, -3,1e-6);
fplot(g,[-3,3]);
function [xfinal, niter, xlist] = fixedpt( gfunc, xguess, tol )
% FIXEDPT: Fixed point iteration for x=gfunc(x).
%
% Sample usage:
% [xfinal, niter, xlist] = fixedpt( gfunc, xguess, tol )
%
% Input:
% gfunc - fixed point function
% xguess - initial guess at the fixed point
% tol - convergence tolerance (OPTIONAL, defaults to 1e-6)
%
% Output:
% xfinal - final estimate of the fixed point
% niter - number of iterations to convergence
% xlist - list of interates, an array of length 'niter'

% First, do some error checking on parameters.
if nargin < 2
fprintf( 1, 'FIXEDPT: must be called with at least two arguments' );
error( 'Usage: [xfinal, niter, xlist] = fixedpt( gfunc, xguess, [tol] )' );
end
if nargin < 3, tol = 1e-6; end

% fcnchk(...) allows a string function to be sent as a parameter, and
% coverts it to the correct type to allow evaluation by feval().
gfunc = fcnchk(gfunc);
x = xguess;
xlist = [ x ];

niter = 0;
done = 0;
while ~done,
xnew = feval(gfunc, x);
xlist = [ xlist; xnew ]; % create a list of x-values
niter = niter + 1;
if abs(x-xnew) < tol, % stopping tolerance for x only
done = 1;
end
x = xnew;
end
xfinal = xnew;
end


Related Solutions

For the equation e^x =x+2, (a) use the fixed point iteration method to determine its two...
For the equation e^x =x+2, (a) use the fixed point iteration method to determine its two roots to eight correct decimal places (you may need to write this equation in two different ways of x = g(x) in order to obtain these two roots); (b) numerically calculate the convergence rates for your converged iterations; (c) compare these numerical convergence rates with the theoretical conver- gence rates we presented in class (also see Theorem 1.6 on page 38 of the textbook).
Create a python code that calculates fixed point iteration method using a for loop.
Create a python code that calculates fixed point iteration method using a for loop.
Use the Fixed-Point Iteration Method to find the root of f ( x ) = x...
Use the Fixed-Point Iteration Method to find the root of f ( x ) = x e^x/2 + 1.2 x - 5 in the interval [1,2].
Consider the following bivariate data. Point A B C D E F G H I J...
Consider the following bivariate data. Point A B C D E F G H I J x 0 1 1 2 3 4 5 6 6 7 y 5 5 6 5 4 3 2 0 1 1 (a) Construct a scatter diagram of the given bivariate data. (Do this on paper. Your instructor may ask you to turn in this work.) (b) Calculate the covariance. (Give your answer correct to two decimal places.) (c) Calculate sx and sy. (Give...
Use a fixed-point iteration to determine the solution (in [0,1])ofthe equation x = 1.5cos(x). Use a...
Use a fixed-point iteration to determine the solution (in [0,1])ofthe equation x = 1.5cos(x). Use a starting value of 0.5. How many iterations does it take before you have an answer which is accurate in the first 2 digits? ...in the first 3 digits?...in the first 4 digits? What happens if you change the starting value to 0.7?...to 0.0? Does the fixed-point iteration converge? If not, modify the equation so that x = cos(x)/30 + 44x/45. Does the iteration converge...
Consider the following grammar G: E -> E + T | T T -> T F...
Consider the following grammar G: E -> E + T | T T -> T F | F F -> F* | a | b This grammar can be used to generate regular expressions over the alphabet {a,b} with standard precedence rules. Show your solution for each of the following 5 points:     1. Remove left recursion and write the resulting grammar G1.     2. For the grammar G1, compute and write the sets FIRST for every right hand side...
Consider the following context-free grammar G: E ® T + E ® * T i E...
Consider the following context-free grammar G: E ® T + E ® * T i E ® f i E ® * f + T ® + Questions: (5 points) Compute the Canonical LR(1) Closure set for state I0 for grammar G. (10 points) Compute (draw) the DFA that recognizes the Canonical LR(1) sets of items for grammar G. (5 points) Construct the corresponding Canonical LR(1) parsing table. (10 points) Compute (draw) the DFA for LALR(1). (5 points) Construct LALR(1)...
ALL WITH EXPLANATIONS please :) 12. Consider the following reaction: 2SO2(g)  +  O2(g)  ⇄  2SO3(g)   +E             Which of the following w
ALL WITH EXPLANATIONS please :) 12. Consider the following reaction: 2SO2(g)  +  O2(g)  ⇄  2SO3(g)   +E             Which of the following will not shift the equilibrium to the right?             A.        Adding more O2             B.        Adding a catalyst             C.        Increasing the pressure             D.        Lowing the temperature 13.         Consider the following equilibrium system: CaCO3(s)  ⇄ CaO(s) +  CO2(g)             Which one of the following changes would cause the above system to shift left?             A.        Add more CaO             B.        Remove CaCO3             C.        Increase pressure             D.        Remove CO2 14.         Consider the following equilibrium: SO2Cl2(g)  +  energy  ⇄  SO2(g)  +  Cl2(g)             When the temperature is decreased, the equilibrium shifts             A.        Left...
Show that g(x) = 1/2sin(x-1) has a unique fixed point on the interval [-1,1] Estimate the...
Show that g(x) = 1/2sin(x-1) has a unique fixed point on the interval [-1,1] Estimate the number of iterations required to achieve 10^-2 accuracy
Consider the reaction, 2 D(g) + 3 E(g) + F(g) => 2 G(g) + H(g) When...
Consider the reaction, 2 D(g) + 3 E(g) + F(g) => 2 G(g) + H(g) When H is increasing at 0.85 mol/Ls, how quickly is F decreasing?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT