Hi, i'm trying to create a vector d=zeros(itermax,1), and then update every element of the vector with the value of the variable d_n. These are the script and the function file:
%script
g = @(x) (3*x+2)/(2*x+3);tol = 10^(-10);xn=0.5;y=0.5;z=0.5;x_p=0;x_n=0;iter_max=100;d=zeros(iter_max,1);[xn,d_n] = pfisso(g,tol,iter_max,xn,y,z,d)
function:
function [xn,d_n] = pfisso(g,tol,iter_max,xn,y,z,d)for i= 0:iter_max z=y; %x_(n-1)
y = xn; %x_n
xn=g(xn); %x_(n+1)
d_n= abs(y - z); d(i)=d_n; if (i>=2) && (d_n<=tol) break endendend
The program returns:
Array indices must be positive integers or logical values.Error in pfisso (line 7) d(i)=d_n;Error in lab4es5 (line 10)[xn,d_n] = pfisso(g,tol,iter_max,xn,y,z,d)
Best Answer