Error using * Inner matrix dimensions must agree - using meshplot

1 vue (au cours des 30 derniers jours)
Will
Will le 4 Mar 2014
Commenté : Will le 4 Mar 2014
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;

Réponse acceptée

Mischa Kim
Mischa Kim le 4 Mar 2014
Modifié(e) : Mischa Kim le 4 Mar 2014
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;

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by