Index exceeds the number of array elements (2).

2 visualizaciones (últimos 30 días)
YASIR ARFAT
YASIR ARFAT el 4 de Jul. de 2020
Comentada: Voss el 5 de Jul. de 2020
clear all; clc;
format long
en=10^-50;
q=0.9;
o=0.5;
xi=1;
U=1;
gema=i/(6*i+1);
xn(:,1)=-2;
xn(:,2)=1;
i=2;
tic;
while (norm( xn(:,i)- xn(:,i-1) ) > en)
theta(2)= ((q*i)/(i+3));
Thta(2)=((o*i)/(i+3));
s=0.017;
gema=i/(6*i+1);
r(i)=1/(100*i+1); %is used for r(n)
yn(:,i)= (xn(:,i)+theta(i)*(xn(:,i)-xn(:,i-1)));
y1n(:,i)=(xn(:,i)+Thta(i)*(xn(:,i)-xn(:,i-1)));
cn(:,i)=(yn(:,i)-3*s*U*y1n(:,i));
Sn(:,i)=xn(:,i)+xi*((((1-3*s*U)/(1+s*U*4))*cn(:,i)-xn(:,i)));
xn(:,i+1)= Sn(:,i);
if (xn(:,i) ~= xn(:,i-1))
theta(i+1)= min( 1 /( (i+1)^2 *norm( xn(:,i) - xn(:,i-1) ) ), 0.5 ); % theta reprsents theta
else
theta(i+1)= 0.5;
end
theta(i+1)
i=i+1
end
Out Put:
Index exceeds the number of array elements (2).
Error in theeta_fileVMFB (line 27)
y1n(:,i)=(xn(:,i)+Thta(i)*(xn(:,i)-xn(:,i-1)));

Respuestas (1)

Voss
Voss el 4 de Jul. de 2020
This error happens the second time through the while loop (that is, i == 3). The cause of the error is that Thta only has 2 elements, but this line is trying to reference Thta(3).
  5 comentarios
YASIR ARFAT
YASIR ARFAT el 5 de Jul. de 2020
yes you are right but i need your help please run this program or tell me how to reduce this error and then it is ready for output so please solve this problems or tell me in above mention matlab code before what i do then this error will remove. Thankyou.
Voss
Voss el 5 de Jul. de 2020
There are many ways to avoid running into this error, but just having the code run without errors doesn't mean the code is correct or the results are right. Like Walter Roberson observed, the variable theta grows by one element each time through the while loop, but Thta does not. Perhaps correcting this inconsistency in an appropriate manner would be all you need to do. (But I cannot say what is appropriate and whether this would be sufficient because I don't know what theta and Thta represent and I don't know what the code is supposed to be doing.)

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by