How do I plot this vector curve?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jason Shu
am 19 Okt. 2017
Bearbeitet: Cam Salzberger
am 19 Okt. 2017
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?
0 Kommentare
Akzeptierte Antwort
Cam Salzberger
am 19 Okt. 2017
Bearbeitet: Cam Salzberger
am 19 Okt. 2017
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Fit Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!