I'm trying to make a function in MATLAB for solving 2 equations using successive substitution. However, I am getting a nested function error( function NLSS), even though the function isn't nested. Here is the code:
X=[0.75 0.25]; %N-dimensional array, first guess then solution
Y=[0 0];
G(1)=(sqrt(1-(X(2))^2)); %right hand side functions
G(2)=1-X(1); %right hand side functions
MAXIT=10;
ITEST=1;
function [X,counter] =NLSS(X,Y);
while ITEST==1
counter=0;
counter=counter+1;
X(1)=(sqrt(1-(X(2))^2));
X(2)=1-X(1);
if abs(Y(1)-X(1))<0.00000001
ITEST=3;
end
if counter>MAXIT
ITEST=2;
end
Y(1)=X(1);
Y(2)=X(2);
end;
end;
fprintf('answer for X1 is %d and X2 is %d and ITEST is %d.\n',X(1),X(2),ITEST);
fprintf('number of interations is %d.\n',counter);