How to draw a tilt field in matlab

I was looking for a way to draw slope fields in Matlab.

Here is what I am looking for:

I have an equation

dy/dx = f(x,y) 

or

 dx/dt = f(x,y) dy/dt = g(x,y) 

and I want to do it in a beautiful way

Since the only answer about this here did not answer my question, it took me a while to find how to do this.

In addition, because this is not what I do all the time in matlab (most likely, until next time I will need it, I will forget it) I am creating a note for me on how to do this.

If you find this useful, feel free to raise

+4
source share
1 answer

so here is the equation:

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

This is the code that will help you complete the task:

 [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 dll field. You can read it here . But I did not check it for myself.

+8
source

All Articles