2
我想在MATLAB中使用連續替換來求解2個方程。但是,我得到一個嵌套的函數錯誤(函數NLSS),即使該函數沒有嵌套。下面是代碼:在matlab中嵌套的函數錯誤
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);
謝謝,你的代碼工作。我只需在功能代碼的輸出中添加ITEST。 – user2606257