Plot a parametric curve in MathLab

14 次查看(过去 30 天)
Magnarok
Magnarok 2016-2-24
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)

回答(1 个)

Star Strider
Star Strider 2016-2-24
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.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by