How do I plot this vector curve?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jason Shu
le 19 Oct 2017
Modifié(e) : Cam Salzberger
le 19 Oct 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 commentaires
Réponse acceptée
Cam Salzberger
le 19 Oct 2017
Modifié(e) : Cam Salzberger
le 19 Oct 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Fit Postprocessing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!