tags:

views:

50

answers:

1

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?

+4  A: 

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
gnovice
BTW, what do you mean by `inner matrix dimension`?
For an operation `A*B` the inner matrix dimensions are the columns of `A` and the rows of `B`, which must be equal to perform a matrix multiplication.
gnovice
Where does the `Imaginary part` come from since there is no explicit mentioning of it?
Seems it's more a MATLAB term than math term,right?
@user198729: The imaginary parts come from the `sqrt(cos(t))` term. When `cos(t)` is negative, the square root is imaginary.
gnovice

related questions