Help,Subtracting two unequal vectors gives a zero vector? Is MATLab wrong?

1 visualización (últimos 30 días)
hello
I want to ask you a question about the code that I did. I want to get the equilibrium y to do that, I subtracted two consecutive terms inorder to get a zero n-vector
In my code, when I do a while loop, the equivalent y is 82 but when I subtract the consecutive of the last two terms 81 and 82 I donot get a zero vector but 1 element of this vector zero. I think Matlab considered it as a true case when just 1 element was equal.
I tried doing it using the for loop for example till 250, the equilibrium y was at 183 way far than the 82.
What should I change in the code to make it stop at 183 noting that I am required to plot till equilibrium is reached ( that means using the while loop.)
function [Nt,xe,ye]= PopulationProgress(x,L)
%x=[200000,300000,500,1500]'
i=1;
n=length(x);
temp1=x;
temp2=L*temp1;
Z=zeros(n,1);
while (round(temp1)-round(temp2))~=Z
Nt(:,i)=round(temp1);
Nt(:,i+1)=round(temp2);
temp1=round(temp2);
Y=L*temp1;
temp2=round(Y);
i=i+1;
end;
%for i=1:250
% Nt(:,i)=round(temp1);
% Nt(:,i+1)=round(temp2);
% temp1=round(temp2);
% Z=L*temp1;
% temp2=round(Z);
%end
ye=i;
xe=Nt(:,i);

Respuestas (0)

Categorías

Más información sobre Mathematics 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