Plot a parametric curve in MathLab

15 ビュー (過去 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 Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by