为什么看起来有效的语句在 MATLAB 中会出错?
这是来自这个 问题。
为什么这两个解决方案不起作用,尽管它对我来说看起来非常有效:
>> 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
*
运算符是矩阵乘法运算符,要求其操作数具有匹配的内部矩阵维度。.*
运算符是逐元素乘法运算符,它要求其操作数具有相同的大小(或者其中一个是标量),以便它可以对每个匹配的元素对执行乘法。有关更多详细信息,请参阅此链接。另外,当我运行第二个解决方案时,我没有收到您所出现的绘图错误。我刚刚收到这个警告:
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: