Creating a phase portrait of first order equations using meshgrid and quiver
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Madhav Rajan
am 1 Okt. 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)
Antworten (0)
Siehe auch
Kategorien
Mehr zu Vector Fields finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!