Azzera filtri
Azzera filtri

Creating a phase portrait of first order equations using meshgrid and quiver

10 visualizzazioni (ultimi 30 giorni)
I have the script set up the way I think it should be however the the equation dx/dt=Ax where x is an nx1 solution vector and A is a constant matrix. The x and y intervals are [-2.5:2.5]. Should n also be given in order for me to be able to finish writing this function. The function should take in a matrix A and return the phase portrait.
function [ ] = directionField( A )
x=-2.5:2.5
y=-2.5:2.5
[x,y]=meshgrid(x, y);
dy=A.*?
dx=ones(size(x));
veclength= sqrt(dx.^2+dy.^2);
v=dy./veclength;
u=dx;
scale=0.5
quiver(x,y,u, v,scale)
end
  1 Commento
Madhav Rajan
Madhav Rajan il 1 Ott 2015
I understand that you want to know whether you need the variable 'n' in order to write this function. Since you know the size of 'x', 'n' is not needed but as pointed out in the documentation , the following condition must be satisfied:
length(x) = n and length(y) = m, where [m,n] = size(u) = size(v)

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by