Plot a parametric curve in MathLab
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey, I am completely new to MatLab and is at the moment trying to figure out how to plot this curve into MatLab!
r(t) = t cos t i + t sin t j + ((2 * sqrt(2)) / 3) * t3/2 k, where 0 <= t <= 2*pi.
----------------------------------------------------------------------------------------------
I tried it like this, but got alot of errors:
">> t = 0 : 2*pi
">> i = t*sin(t) //Gives me error "Using *. Inner matrix dimension must agree."
">> j = t*sin(t) //Same error as above.
">> k = ((2 * sqrt(2)) / (3)) * t3/2 //Error: "Using . Inputs must be a scalar and a square matrix."
">> plot3(i,j,k)
0 commentaires
Réponses (1)
Star Strider
le 24 Fév 2016
You need to do element-wise operations (particularly multiplication) in your code. See Array vs. Matrix Operations for the details.
If I understand your code correctly, this will work:
r = @(t) [t .* cos(t); t .* sin(t); ((2 * sqrt(2)) / 3) * t*3/2];
t = linspace(0, 2*pi, 250);
rt = r(t);
figure(1)
plot3(rt(1,:), rt(2,:), rt(3,:))
grid on
xlabel('i')
ylabel('j')
zlabel('k')
Note that the anonymous function ‘r’ creates a (3xN) matrix where the first row corresponds to ‘i’, the second to ‘j’ and the third to ‘k’, so ‘t’ must always be a row vector for the row indexing to work correctly.
0 commentaires
Voir également
Catégories
En savoir plus sur Calculus 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!