2010-05-04 92 views
0

這是一個從這個question爲什麼有效的聲明會在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. 

這有什麼錯以上?

回答

4

*運算符是矩陣乘法運算符,它要求其操作數具有匹配的內部矩陣維度。 .*運算符是單元乘法運算符,它要求其操作數具有相同的大小(或者一個是標量),因此它可以在每對匹配的元素上執行乘法運算。有關更多詳細信息,請參閱this link

另外,當我運行第二個解決方案時,我沒有看到繪圖錯誤。我只是得到這個警告:

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

順便說一句,你是什麼意思的「內矩陣維度」? – user198729 2010-05-04 19:09:11

+1

對於「A * B」操作,內部矩陣維數是「A」的列和「B」的行,它們必須等於執行矩陣乘法。 – gnovice 2010-05-04 19:11:29

+0

由於沒有明確提及它,「虛部」來自哪裏? – user198729 2010-05-04 19:12:16

相關問題