Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

compute the fixed point of the function using the fixed point iteration in MATLA

ID: 671096 • Letter: C

Question

compute the fixed point of the function using the fixed point iteration in MATLAB; don't answer if your going to make up your own code. Just FILL IN where indicated.

function [x1,g1,n] = fixed_point(h,xo,tolr)
nmax = 100;
x1 = zeros(nmax+1,1);
h1 = zeros(nmax+1,1);

error = tolr + 1; % initialize error
count = 0; % initialize iteration count
xnew = xo; % initialize x-value
while error > tolr && count < n_max
count = count + 1;


xo = xnew;
xnew = % !!! FILL IN THE CODE TO UPDATE ITERATION HERE!!!
  
% Store
x1(count+1) = xnew;
h1(count+1) = h(xnew);

error = % !!! FILL IN THE CODE TO FIND ERROR HERE !!!
end

n = count;
x1 = x1(1:n+1);
h1 = h1(1:n+1);

Explanation / Answer

See my comments in the code.

function [x1,g1,n] = fixed_point(h,xo,tolr)
nmax = 100;
x1 = zeros(nmax+1,1);
h1 = zeros(nmax+1,1);

error = tolr + 1; % initialize error
count = 0; % initialize iteration count
xnew = xo; % initialize x-value
while error > tolr && count < n_max
count = count + 1;


xo = xnew;
xnew = h(x0); % Xi+1= h(Xi); !!! FILL IN THE CODE TO UPDATE ITERATION HERE!!!

% Store
%My Comments- here you are logic seems confusing, you already count to 1, but not storing anyting x1(1) & h1(1), you are starting from index 2

x1(count+1) = xnew;
h1(count+1) = h(xnew);

error = xnew-h(x0); %error = | xi+1 - h(xi) |, here xi+1 = xnew, x0= h(xi) as in above lines x0 stores xi !!! FILL IN THE CODE TO FIND ERROR HERE !!!
%we need difference i.e positive error, that's why this two lines, if you donot want this lines, then |x| = +x operator is needed in matab. replace above line with that syntax

if(error < 0)
error = error * -1;
end
end

n = count;
x1 = x1(1:n+1);
h1 = h1(1:n+1);