|
"David Migl" <migl.spam@gmail.com> wrote in message <g1qla2$ise
$1@fred.mathworks.com>...
> Hi,
>
> I am trying to graph the parametric function
> x=t*cos(t)
> y=t*sin(t)
>
> Matlab doesn't like these equations; it stops at the first
> one and gives me the error message:
>
> ??? Error using ==> mtimes
> Inner matrix dimensions must agree.
>
> My script runs like this:
> clear; clc; close all;
> t=linspace (0,6*pi)
> x=t*cos(t)
> y=t*sin(t)
> plot(x,y)
>
> I am completely baffled why I should receive the error
> message. I begin my .m file by clearing everything: clear;
> clc; close all;, and the calculations I am doing have
> absolutely nothing to do with matrices.
>
> Does anyone have any insights into this?
----------------
You are using the '*' operator improperly. What you want is '.*' instead.
When you say
t*cos(t)
matlab attempts to do matrix multiplication on two 100-element row vectors
and this is impossible for it to do, because the inner dimensions do not
match, just as the error message says.
Write
x = t.*cos(t);
y = t.*sin(t);
Roger Stafford
|