How do I plot this vector curve?

2 次查看(过去 30 天)
Very new to matlab, still learning.
How do i plot the curve parametrized by P(t) = (1 - cos t)i + (1 + 2t + t^2)j for 0<=t<=1?
I have tried
x=linspace(-1,1)
i = 1 - cos(t)
j= 1 + 2*t + t.^2
plot(x,i,x,j)
but it says "Vectors must be the same length." Any idea what I'm doing wrong here?

采纳的回答

Cam Salzberger
Cam Salzberger 2017-10-19
编辑:Cam Salzberger 2017-10-19
Hello Jason,
"(1-cos(t))i" means that this point will be at the x-coordinate "1-cos(t)" for time t. Similarly for "j" -> y-coordinate. So you're on the right track, but the trick is to know that MATLAB doesn't care what time it is while plotting. It only wants to know the x and y coordinates.
t = linspace(-1, 1, 10);
x = 1 - cos(t);
y = 1 + 2*t + t.^2;
plot(x, y)
The error was likely because you were defining "x" instead of "t" in the first line, but you had an existing "t" value left over from before. Be careful about that when writing scripts.
Also, I'd recommend against using "i" or "j" as variable names in MATLAB, since they have a built-in meaning as the imaginary unit.
-Cam

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by