简体   繁体   English

如何在Matlab中绘制斜率场?

[英]How to plot slope fields in Matlab?

I am new to Matlab (literally just downloaded it) and I would like to know how to create a slope field and integral curves. 我是Matlab的新手(实际上只是下载了它),我想知道如何创建斜率场和积分曲线。

My equation is dy/dx = x^2/(1-y^2). 我的方程是dy / dx = x ^ 2 /(1-y ^ 2)。

My attempt at code is: 我的代码尝试是:

Ffun = @(X,Y)X.^2./(1-Y.^2);               % function f(x,y)
[X,Y]=meshgrid(-5:.5:5,-5:.5:5); % choose the plot sizes
DY=Ffun(X,Y); DX=ones(size(DY)); % generate the plot values 
quiver(X,Y,DX,DY);
hold on;
contour(X,Y,DY,10); 

I keep getting: "Warning: Matrix is singular to working precision. In @(X,Y)X^2/(1-Y^2) I also get blank graphs. 我不断得到:“警告:矩阵对于工作精度是唯一的。在@(X,Y)X^2/(1-Y^2)我还得到了空白图形。

Also, it would be nice if I could get the positive, negative, and zero slopes in different colors. 另外,如果我能获得不同颜色的正,负和零斜率,那就太好了。

Help would be appreciated, thank you! 帮助将不胜感激,谢谢!

You are producing inf values when evaluating this function, as it has poles around Y=+-1. 您在评估此函数时会产生inf值,因为它的极点在Y = +-1附近。 The inf makes the plot to scale to absurdity.... To still plot this you can transform all inf values to NaN (not a number does not show in a plot) as follows: inf使图按比例缩放以荒谬。...仍要绘制此图,您可以将所有inf值转换为NaN (图中未显示数字):

DY(isinf(DY))=NaN;
quiver(X,Y,DX,DY);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM