Plot a parametric curve in MathLab

조회 수: 14 (최근 30일)
Magnarok
Magnarok 2016년 2월 24일
답변: Star Strider 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