为什么看起来有效的语句在 MATLAB 中会出错?

发布于 2024-08-30 23:52:45 字数 530 浏览 2 评论 0原文

这是来自这个 问题

为什么这两个解决方案不起作用,尽管它对我来说看起来非常有效:

>> t = -pi:0.1:pi;
>> r = ((sin(t)*sqrt(cos(t)))*(sin(t) + (7/5))^(-1)) - 2*sin(t) + 2 ;
??? Error using ==> mtimes
Inner matrix dimensions must agree.

>> t = -pi:0.1:pi;
>> r = ((sin(t).*sqrt(cos(t))).*(sin(t) + (7/5)).^(-1)) - 2*sin(t) + 2 ;
>> plot(r,t)
??? Error using ==> plot
Vectors must be the same lengths.

以上有什么问题吗?

It's from this question

Why the two solutions doesn't work, though it looks very valid for me:

>> t = -pi:0.1:pi;
>> r = ((sin(t)*sqrt(cos(t)))*(sin(t) + (7/5))^(-1)) - 2*sin(t) + 2 ;
??? Error using ==> mtimes
Inner matrix dimensions must agree.

>> t = -pi:0.1:pi;
>> r = ((sin(t).*sqrt(cos(t))).*(sin(t) + (7/5)).^(-1)) - 2*sin(t) + 2 ;
>> plot(r,t)
??? Error using ==> plot
Vectors must be the same lengths.

What's wrong with the above?

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

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

发布评论

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

评论(1

香草可樂 2024-09-06 23:52:45

* 运算符是矩阵乘法运算符,要求其操作数具有匹配的内部矩阵维度。 .* 运算符是逐元素乘法运算符,它要求其操作数具有相同的大小(或者其中一个是标量),以便它可以对每个匹配的元素对执行乘法。有关更多详细信息,请参阅此链接

另外,当我运行第二个解决方案时,我没有收到您所出现的绘图错误。我刚刚收到这个警告:

Warning: Imaginary parts of complex X and/or Y arguments ignored

The * operator is the matrix multiplication operator, which requires its operands to have matching inner matrix dimensions. The .* operator is the element-wise multiplication operator, which requires its operands to have the same size (or for one to be a scalar) so it can perform multiplication on each matching pair of elements. See this link for more detail.

Also, I don't get the plotting error you do when I run the second solution. I just get this warning:

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