登录论坛

查看完整版本 : 为什么有效的查找语句会在MATLAB中给出错误?


poster
2019-12-10, 20:41
就是这个问题 (https://stackoverflow.com/questions/2720180/matlab-heart-curve)銆/ p> 为什么这两个解决方案不起作用,尽管对我来说看起来很有效:

>> 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. 上面有什么问题?



回答:

*运算符是矩阵乘法运算符,它要求其操作数具有匹配的内部矩阵维。 .*运算符是逐元素的乘法运算符,它要求其操作数具有相同的大小(或一个为标量),以便可以对每个匹配的元素对执行乘法。有关更多详细信息,请参见此链接 (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/arithmeticoperators.html) 。

另外,当我运行第二个解决方案时,我没有得到绘制错误。我刚收到以下警告:

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

更多&回答... (https://stackoverflow.com/questions/2768133)