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

Image Analyst
Image Analyst 2011년 11월 22일
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

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 22일

0 개 추천

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

Image Analyst
Image Analyst 2011년 11월 22일
They give the same thing. When I actually tried the code I found the problem was "V(:, col)=(A.^t)*V0; " as given in my comment above, and I also discovered the transpose error.
Haley
Haley 2011년 11월 22일
there isnt a line 48.
and the V0 is given in the problem as 42, 0, 95
Walter Roberson
Walter Roberson 2011년 11월 22일
The error message you posted was
??? Error using ==> project at 48
Valid object handles must be supplied
So MATLAB thinks there is a line 48. If you were to post the traceback we could try to debug -that- problem.
You are right, V0 is given in the code as [42, 0, 95] . That makes it a 1 x 3 matrix, and that matrix is appearing on the right hand side of a matrix multiply in which the left hand side is 3 x 3 . You cannot matrix-multiply a 3 x 3 matrix by a 1 x 3 matrix: in order to be able to do a matrix multiply, the second dimension (i.e., 3) of the first matrix must be the same as the first dimension of the second matrix (i.e, 1). Now, if you were to do a matrix multiply with the transpose of V0, then that would be (3 x 3) * (3 x 1) and that would be mathematically fine, producing a 3 x 1 answer.
Haley
Haley 2011년 11월 22일
it stops at line 31
Haley
Haley 2011년 11월 22일
i have a new error now
Walter Roberson
Walter Roberson 2011년 11월 22일
You only posted 19 lines of code up to and including the ylabel() line. Which line is line 31? Please post the complete traceback showing the error message and showing MATLAB's idea of the line it is having problems with.
Have you tried commanding
dbstop if error
at the command line, letting it run, and examining all of the variables on the line it stops at?
Haley
Haley 2011년 11월 23일
It stops at line 22. I put where line 22 is.
Haley
Haley 2011년 11월 23일
??? 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')
Haley
Haley 2011년 11월 23일
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 2011년 11월 23일
Replace
V(:,1)=(A^t)*V0;
with
V(:,i)=(A^t)*V0;
and, of course, restore your plot() command.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2011년 11월 22일

0 개 추천

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

Haley
Haley 2011년 11월 22일
what does that mean?
Haley
Haley 2011년 11월 22일
I put the semicolon and it didn't work
Image Analyst
Image Analyst 2011년 11월 22일
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 2011년 11월 22일
I got the same error as you this time but it still is not working

댓글을 달려면 로그인하십시오.

Haley
Haley 2011년 11월 23일

0 개 추천

I figured it out. Thanks so much y'all!

댓글 수: 8

Image Analyst
Image Analyst 2011년 11월 23일
Yes, the debugger can be a more powerful tool than "Answers." Glad you learned how to use it.
Michael Roberts
Michael Roberts 2017년 4월 5일
please help; how did you figure it out?
Michael Roberts
Michael Roberts 2017년 4월 5일
my plot is still blank, can someone please tell me how to get something to show up in my plot
Image Analyst
Image Analyst 2017년 4월 5일
Figure out what? How to use the debugger? See this link
To get something to show up in your plot, use the plot() function. That's about all we can say unless we see your code. If you want more help, read this first then start a new question.
Michael Roberts
Michael Roberts 2017년 4월 5일
편집: Walter Roberson 2017년 4월 5일
to clarify: i have gotten this far in my code, but my plot is still empty. my code is
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')
I just can't figure out why my plot is blank
Walter Roberson
Walter Roberson 2017년 4월 5일
A = [ 0 0 0.43; 0.6 0 0; 0 0.75 0.96 ];
T = [ 0 1 2 3 4 5 10 20 25 50 75 ];
V0 = [ 42, 0, 95 ]';
V=zeros(3,length(T));
for i = 1 : length(T)
V(:,i)=(A^T(i))*V0;
end
figure
T2=log(T);
V2=log(V);
plot( T2, V2(1,:), 'b', T2, V2(2,:), 'g', T2, V2(3,:), 'r')
legend('calves','yearlings','adults')
title('population versus time')
xlabel('time')
ylabel('population')
Image Analyst
Image Analyst 2017년 4월 5일
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 2017년 4월 5일
Thank you very much Walter and Mr. italicizing image analyst

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

태그

질문:

2011년 11월 22일

댓글:

2017년 4월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by