Reputation: 55
I want to plot a curve with parametrisation x=... , y=... and z=... (see below). I keep getting error messages, mostly 'inconsistent multiplication'. Here is my code:
t = linspace(0,4*%pi)
x = (4+sin(63*t))*cos(3*t)
y = (4+sin(63*t))*sin(3*t)
z = cos(3*t)
param3d(x,y,z)
Could someone explain why I'm getting this error message or how my code should be corrected? I also tried to define x, y and z as functions.
Upvotes: 1
Views: 3578
Reputation:
From the documentation of * operator:
Element-wise multiplication is denoted
x.*y
. Ifx
ory
is scalar (1x1 matrix).*
is the same as*
.
So, in your case the formulas should be written as (4+sin(63*t)).*cos(3*t)
because you want to multiply two arrays element-wise. Without the dot, the asterisk means matrix multiplication, and that fails because of mismatching size.
Examples:
[1, 2] .* [3, 4] // returns [3, 8]
[1, 2] * [3, 4] // error; one can't multiply a 1-by-2 matrix by another 1-by-2 matrix
One can also write 3.*t
but here . is redundant since there is only one way to multiply a vector by a scalar.
Upvotes: 1