Borrar filtros
Borrar filtros

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

10 visualizaciones (últimos 30 días)
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 comentario
Madhav Rajan
Madhav Rajan el 1 de Oct. de 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)

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by