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

1 次查看(过去 30 天)
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 个评论
Madhav Rajan
Madhav Rajan 2015-10-1
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)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by