如何在八度音阶中绘制矢量?

时间:2018-02-17 10:34:16

标签: vector plot octave

我想制作一个程序,添加两个向量并将它们与它们的添加一起绘制。但他们必须是位置向量。

我尝试创建v1=[0;2]v2=[1;3]但是使用plot显示它们会产生许多分散点。

如何指定向量的起始位置,例如使v1v2从原点开始?

2 个答案:

答案 0 :(得分:0)

我通常使用quiver函数执行您所描述的内容,其目的是绘制矢量字段。你的例子可以用

绘制
   xx=[0;2];
   yy=[0;0];
   quiver(xx,yy,[0;1],[2;3],0,"linewidth",4);axis equal;xlim([-4 4]);ylim([0 5]);grid on;[![enter image description here][1]][1]

它产生以下输出:

enter image description here

向量的起点由以下两种变量xxyy指定:n-th向量的起点由[xx(n,1);yy(n,1)]给出(请查看help meshgrid以获取相关信息。基本上,meshgrids只是定义函数域的一种方法,这里恰好是一个向量字段。

答案 1 :(得分:0)

以下是在Octave中绘制数学向量的示例:

clf
xs=[0 0 1 5 0]
ys=[0 0 7 1 0]
xe=[5 1 5 1 6]
ye=[1 7 1 7 8]
q=1;
h=quiver(xs(q),ys(q),xe(q),ye(q), 0,'b');
hold on
set (h, "maxheadsize", 0.033);
q=3;
h=quiver(xs(q),ys(q),xe(q),ye(q), 0,'--b');
set (h, "maxheadsize", 0.033);
q=2;
h=quiver(xs(q),ys(q),xe(q),ye(q), 0,'r');
set (h, "maxheadsize", 0.033);
q=4;
h=quiver(xs(q),ys(q),xe(q),ye(q), 0,'--r');
set (h, "maxheadsize", 0.033);
q=5;
h=quiver(xs(q),ys(q),xe(q),ye(q), 0,'g');
set (h, "maxheadsize", 0.033);
axis("square")
grid on
hold off