Error using * Inner matrix dimensions must agree - using meshplot

조회 수: 1 (최근 30일)
Will
Will 2014년 3월 4일
댓글: Will 2014년 3월 4일
I have been trying to draw the direction fields of some first order differential equations and sometimes I can get it to work, others not.
This is an example of a problem I have just had:
To sketch the direction field of dy/dt - 2*y = t^2 . e^(2t)
I have tried the following:
>> [t y]=meshgrid(0:0.5:2,-4:0.5:4); >> dy=t.^2*exp(2.*t)+2.*y;
But an it immediately states there is an error: Error using * Inner matrix dimensions must agree.
I can't see what the problem is because in other instances this error does not occur. For example, this worked perfectly:
>> [t y]=meshgrid(-4:0.5:4,-4:0.5:4); >> dy=t - 3*y +exp(-2*t); >> dt=ones(size(dy)); >> L=sqrt(1+dy.^2); >> quiver (t, y, dt./L, dy./L, 0.5), axis tight;

채택된 답변

Mischa Kim
Mischa Kim 2014년 3월 4일
편집: Mischa Kim 2014년 3월 4일
Will, use
[t y] = meshgrid(0:0.5:2,-4:0.5:4);
dy = t.^2.*exp(2*t) + 2.*y; % need to use dot operators all the way
dt = ones(size(dy));
L = sqrt(1 + dy.^2);
quiver (t, y, dt./L, dy./L, 0.5)
axis tight;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by