How do I plot this vector curve?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Jason Shu
il 19 Ott 2017
Modificato: Cam Salzberger
il 19 Ott 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 Commenti
Risposta accettata
Cam Salzberger
il 19 Ott 2017
Modificato: Cam Salzberger
il 19 Ott 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Fit Postprocessing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!