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

조회 수: 1 (최근 30일)
Blake
Blake 2015년 9월 29일
댓글: Madhav Rajan 2015년 10월 1일
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