Matlab quiver函数用法 - 画矢量箭头图

提要:

  • quiver (x, y,u,v)在点(x,y)处画(u,v)所定义的向量箭头。x,y,u,v必须是维度和元素数都一样的矩阵。如果是一维数组的话,x,y,u,v的元素数必须一致。quiver函数会自动调整箭头的长度以适应显示
  • quiver(x,y,u,v,scale)scale 用于限定箭头的长度,如果scale = 1 则等值显示矢量的长度,而scale = 0.2 则显示0.2倍的矢量长度。
  • quiver(u,v)在x-y平面上均匀地画箭头图
  • quiver(x,y,u,v,LinSpec)用于限定箭头的属性,比如颜色,线型等。

quiver就是“箭筒,箭套”的意思
Quiver meaning

quiver用于画矢量函数的箭头图(也叫速度图)(quiver plot, velocity vector plot)
举一个矢量函数的例子:
F ⃗ = i ⃗ x + j ⃗ y \vec{F}=\vec{i}x+\vec{j}y F =i x+j y
如下图,你可以把这个函数看作位置矢量 r ⃗ \vec{r} r ,图中每一个箭头的方向都是向径(即从原点出发的一条直线),并且它的长度等于它到原点的距离。
\vec{F}=\vec{i}x+\vec{j}y
quiver (x, y,u,v)在点(x,y)处画(u,v)所定义的向量箭头。x,y,u,v必须是维度和元素数都一样的矩阵。如果是一维数组的话,x,y,u,v的元素数必须一致。quiver函数会自动调整箭头的长度以适应显示。

%%  draw the velocity vector arrow of the vector function  i*x + j*y 
% generate grids in a sub-definition area
clc
x = -1:0.5:1;
y = -1:0.5:1;

% generate the function values
u = x;
v = y;

% draw vector arrow graph
quiver(x, y, u, v)
text(0.5, 0, '$\leftarrow \vec{F}=\vec{i}x + \vec{j}y $', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
grid on
axis equal

\vec{F}=\vec{i}x+\vec{j}y_line
quiver(x,y,u,v,scale)scale 用于限定箭头的长度,如果scale = 1 则等值显示矢量的长度,而scale = 0.2 则显示0.2倍的矢量长度。比如以上的代码,若加入scale参数,则输出图像如下:

%%  draw the velocity vector arrow of the vector function  i*x + j*y 
% generate grids in a sub-definition area
clc
x = -1:0.5:1;
y = -1:0.5:1;

% generate the function values
u = x;
v = y;

% draw vector arrow graph
scale = 0.2
quiver(x, y, u, v,scale)
text(0.5, 0, '$\leftarrow \vec{F}=\vec{i}x + \vec{j}y $', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
grid on
axis equal

\vec{F}=\vec{i}x+\vec{j}y_line_scale=2

quiver(u,v)在x-y平面上均匀地画箭头图
比如函数 F ⃗ = − i ⃗ y + j ⃗ x x 2 + y 2 \vec{F}=\frac{ -\vec{i}y+\vec{j}x}{\sqrt{x^{2}+y^{2}} } F =x2+y2 i y+j x 使用quiver(x,y,u,v,scale)书写代码:

%%  draw the velocity vector arrow of the vector function  (i*y + j*x)/sqrt(x^2 + y^2)
% generate grids in a sub-definition area
clc

R = 2:2:6;
theta = -pi:pi/4:pi;
x = R'*cos(theta);
y = R'*sin(theta);

% generate the function values
rr = sqrt(x.^2 + y.^2);
fx = -y./rr;
fy = x./rr;
%[FX,FY] = meshgrid(fx,fy);

% draw vector arrow graph
scale = 0.2;
quiver(x, y, fx, fy,scale)
text(4, 2, '$\vec{F}=\frac{ -\vec{i}y+\vec{j}x}{\sqrt{x^{2}+y^{2}} } $', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
grid on
axis equal

输出的图像为
\vec{F}=\frac{ -\vec{i}y+\vec{j}x}{\sqrt{x{2}+y{2}} }
而我们用quiver(u,v)替换掉quiver(x,y,u,v,scale),代码变为:

%%  draw the velocity vector arrow of the vector function  (i*y + j*x)/sqrt(x^2 + y^2)
% generate grids in a sub-definition area
clc

R = 2:2:6;
theta = -pi:pi/4:pi;
x = R'*cos(theta);
y = R'*sin(theta);

% generate the function values
rr = sqrt(x.^2 + y.^2);
fx = -y./rr;
fy = x./rr;
%[FX,FY] = meshgrid(fx,fy);

% draw vector arrow graph
scale = 0.2;
quiver(fx, fy,scale)
text(4, 2, '$\vec{F}=\frac{ -\vec{i}y+\vec{j}x}{\sqrt{x^{2}+y^{2}} } $', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
grid on
axis equal

输出的箭头图不再是环形分布,而变成x-y平面上的均匀分布:
\vec{F}=\frac{ -\vec{i}y+\vec{j}x}{\sqrt{x{2}+y{2}} }_uniform_distribution
quiver(x,y,u,v,LinSpec)用于限定箭头的属性,比如颜色,线型等。
示例代码:

%%  draw the velocity vector arrow of the vector function  (i*y + j*x)/sqrt(x^2 + y^2)
% generate grids in a sub-definition area
clc

R = 2:2:6;
theta = -pi:pi/4:pi;
x = R'*cos(theta);
y = R'*sin(theta);

% generate the function values
rr = sqrt(x.^2 + y.^2);
fx = -y./rr;
fy = x./rr;
%[FX,FY] = meshgrid(fx,fy);

% draw vector arrow graph
scale = 0.2;
quiver(x, y, fx, fy,scale,'.r')
text(4, 2, '$\vec{F}=\frac{ -\vec{i}y+\vec{j}x}{\sqrt{x^{2}+y^{2}} } $', 'HorizontalAlignment', 'left', 'Interpreter', 'latex', 'FontSize', 15);
grid on
axis equal

LinSpec_Matlab_Quiver

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值