Error using * Inner matrix dimensions must agree - using meshplot

1 visualizzazione (ultimi 30 giorni)
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;

Risposta accettata

Mischa Kim
Mischa Kim il 4 Mar 2014
Modificato: Mischa Kim il 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;

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by