如何在matlab中绘制斜率场 [英] how to draw a slope field in matlab

查看:488
本文介绍了如何在matlab中绘制斜率场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种在Matlab中绘制坡度场的方法.

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

这是我要找的东西:

我有一个方程式

dy/dx = f(x,y)

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

我想用一种很好的方式绘制它

and I want to draw it in a nice way

因为仅有的回答此处没有回答我的问题,我花了一些时间来找到解决方法.

Because the only answer about it here was not answering my question, it took me some time to find how to do this.

此外,因为这不是我一直在matlab中做的事情(很可能要等到下一次我需要时,我会忘记它),所以我正在为我创建一个备忘录,该怎么做.

Also because this is not something I am doing all the time in matlab (most probably till the next time I will need it, I will forget it) I am creating a memo for me how to do this.

如果您觉得有用,请随时投票

If you will find it useful, feel free to upvote

推荐答案

所以这是等式:

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);

也可以使用dfield软件包.您可以在此处阅读.但是我还没有亲自测试过

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

这篇关于如何在matlab中绘制斜率场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆