how to draw a slope field in matlab

so here is the equation:

dx/dt = x^2-3xy+y
dy/dt = -5x+sin(yx)

That is the code, which will help to do the job:

[x,y] = meshgrid(-2:0.2:2);
dx = x.^2-3*x.*y+y;
dy = -5*x+sin(x.*y);
r = ( dx.^2 + dy.^2 ).^0.5;
px = dx./r;
py = dy./r;
quiver(x,y,px,py);

It is also possible to use the package dfield. You can read it here. But I have not tested it for myself

2 thoughts on “how to draw a slope field in matlab”

  1. whoah this blog is wonderful i really like reading your articles. Keep up the great paintings! You realize, a lot of people are hunting round for this info, you could help them greatly.

    Reply

Leave a Comment