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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by