如何在 Octave 上绘制函数微分图?

发布于 2025-01-15 22:16:02 字数 732 浏览 3 评论 0原文

我从一开始就想学习三角学。 所以我可以通过将这些命令作为命令来绘制曲线。

x1 = linspace(-2*pi, 2*pi)
y1 = cos(x1)
plot(x1, y1)

但如果我尝试这样做,

x1 = linspace(-2*pi, 2*pi)
y2 = diff(cos(x1))
plot(x1, y1) 

我会收到一条错误消息,指出

error: __plt2vv__: vector lengths must match error: called from     __plt__>__plt2vv__ at line 487 column 5     __plt__>__plt2__ at line 247 column 14     __plt__ at line 112 column 18     plot at line 229 column 10

“但是,我确实获得了 y2 = diff(cos(x1)) 的值,由于此错误,我无法绘制任何内容。”

注意:我知道 sin(x) 的微分是 cos(x),我可以只使用 cos(x),但是不能'我这样做吗?

尝试了 diff(cos(90)) 我得到了

ans = \[\](0x0)

I was trying to learn trigonometry from the beginning.
so I can plot a curve by giving these as commands.

x1 = linspace(-2*pi, 2*pi)
y1 = cos(x1)
plot(x1, y1)

But If I try to do this,

x1 = linspace(-2*pi, 2*pi)
y2 = diff(cos(x1))
plot(x1, y1) 

I receive an error stating

error: __plt2vv__: vector lengths must match error: called from     __plt__>__plt2vv__ at line 487 column 5     __plt__>__plt2__ at line 247 column 14     __plt__ at line 112 column 18     plot at line 229 column 10

However, I do get values for y2 = diff(cos(x1)), I can't plot anything because of this error.

Note: I know the differentiation of sin(x) is cos(x) and I can just use cos(x), but can't I do it this way?

Tried diff(cos(90)) I got

ans = \[\](0x0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末骤雨初歇 2025-01-22 22:16:02

diff 比其输入短一个元素,因为它是差异 [v(2)-v(1), v(3)-v(2), ...]< /代码>。

您需要执行类似 y2 = [NaN, diff(cos(x1))]; 的操作来将数组填充到与 x1 相同的大小。

请注意,这当然会导致偏移,您需要一个 中心差分 方法而不是前向差分方法(如 diff)来保持事物的良好对齐。

diff is one element shorter than its input, because it it the differences [v(2)-v(1), v(3)-v(2), ...].

You need to do something like y2 = [NaN, diff(cos(x1))]; to pad your array to be the same size as x1.

Note that of course this causes an offset, you would need a central differencing method instead of a forward difference method (like diff) to keep things well-aligned.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文