error?

2 visualizaciones (últimos 30 días)
Haley
Haley el 22 de Nov. de 2011
Comentada: Michael Roberts el 5 de Abr. de 2017
A = [ 0 0 0.43; 0.6 0 0; 0 0.75 0.96 ];
T = [ 1 2 3 4 5 10 20 25 50 75 ];
V0 = [ 42, 0, 95 ]';
V=zeros(3,length(T));
V(:,1)=V0;
i=0;
for t=T
i=i+1;
V(:,1)=(A^t)*V0;
end
figure
T=[0 1 2 3 4 5 10 20 25 50 75];
T2=log(T);
V2=log(V);
LINE 22 plot( T2, V2(1,:), 'b', T2, V2(2,:), 'g', T2, V2(3,:), 'r')
%legend('calves','yearlings','adults')
title('population versus time')
xlabel('time')
LINE 30 ylabel('population')
THAT ERROR WENT AWAY. NOW IT SAYS....
??? Error using ==> plot Vectors must be the same lengths.
Error in ==> project3 at 22 plot( T2, V2(1,:), 'b', T2, V2(2,:), 'g', T2, V2(3,:), 'r')
  1 comentario
Image Analyst
Image Analyst el 22 de Nov. de 2011
Try this:
V0 = [ 42; 0; 95 ]
V=zeros(3,length(T)+1);
V(:,1)=V0;
col = 1;
for t=T
col = col+1;
V(:, col)=(A.^t)*V0;
end

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Nov. de 2011
Which is line 48? Please show the traceback.
Image Analyst has proposed (A.^t)*V0 but I think you do want (A^t)*V0 . An array raised to a power is appropriate for a stocastic process. However, when you raise a 3 x 3 matrix to a power, you get out a 3 x 3 matrix. You then try to multiply that by a 1 x 3 matrix, which is going to be an error. I think your definition of V0 should not have the transpose at the end, and should just be
V0 = [ 42; 0; 95 ];
  10 comentarios
Haley
Haley el 23 de Nov. de 2011
okay so i i edited it again and it looks like this:
A = [ 0 0 0.43; 0.6 0 0; 0 0.75 0.96 ];
T = [ 1 2 3 4 5 10 20 25 50 75 ];
V0 = [ 42, 0, 95 ]';
V=zeros(3,length(T));
V(:,1)=V0;
i=0;
for t=T
i=i+1;
V(:,1)=(A^t)*V0;
end
figure
T=[0 1 2 3 4 5 10 20 25 50 75];
%legend('calves','yearlings','adults')
title('population versus time')
xlabel('time')
ylabel('population')
.
the problem is the graph is blank
Walter Roberson
Walter Roberson el 23 de Nov. de 2011
Replace
V(:,1)=(A^t)*V0;
with
V(:,i)=(A^t)*V0;
and, of course, restore your plot() command.

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 22 de Nov. de 2011
Well I think
figure T=[0 1 2 3 4 5 10 20 25 50 75];
evaluates to
figure 0 1 2 3 4 5 10 20 25 50 75;
and you don't have figures with those ID numbers. Try putting a semicolon after figure or splitting that line into two lines.
  4 comentarios
Image Analyst
Image Analyst el 22 de Nov. de 2011
OK, I see you now edited it so that figure is on a separate line but I don't get the error you did. When I run your code it says
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> test at 11
V(:,1)=(A^t)*V0;
Did you perhaps mean A .^ t to do an element-by-element raising to a power?
Haley
Haley el 22 de Nov. de 2011
I got the same error as you this time but it still is not working

Iniciar sesión para comentar.


Haley
Haley el 23 de Nov. de 2011
I figured it out. Thanks so much y'all!
  8 comentarios
Image Analyst
Image Analyst el 5 de Abr. de 2017
It's blank because you didn't use plot() like I recommended. Walter did use it and so his code does show data.
Michael Roberts
Michael Roberts el 5 de Abr. de 2017
Thank you very much Walter and Mr. italicizing image analyst

Iniciar sesión para comentar.

Categorías

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