필터 지우기
필터 지우기

A table of s versus t.

조회 수: 2 (최근 30일)
jay jay
jay jay 2022년 12월 12일
편집: Davide Masiello 2022년 12월 12일
Trying to make a table of s versus t and printing the results to both the screen and to the file.
r = 9 cm, ω = 100 revolutions per second, and b = 14 cm.
0 ≤ t ≤ 0.01 s. Using 20 subdivisions on the t
domain.
r=9
omega=100
b=14
t=0:20:0.01
s(t) = r* cos(2*pi*omega*t)+ sqrt((b^2)-(r^2)*(sin(2*pi*omega*t)^2))
table(s,t)
what is wrong with this code?

답변 (2개)

Les Beckham
Les Beckham 2022년 12월 12일
편집: Les Beckham 2022년 12월 12일
r=9;
omega=100;
b=14;
t = linspace(0, 0.01, 20) % <<< use linspace instead to generate your t vector
t = 1×20
0 0.0005 0.0011 0.0016 0.0021 0.0026 0.0032 0.0037 0.0042 0.0047 0.0053 0.0058 0.0063 0.0068 0.0074 0.0079 0.0084 0.0089 0.0095 0.0100
% remove the (t) on the left side and use .^2 to do element-wise operation
s = r* cos(2*pi*omega*t)+ sqrt((b^2)-(r^2)*(sin(2*pi*omega*t).^2))
s = 1×20
23.0000 22.2040 19.9647 16.7222 13.1584 10.0063 7.7015 6.2396 5.4133 5.0442 5.0442 5.4133 6.2396 7.7015 10.0063 13.1584 16.7222 19.9647 22.2040 23.0000
table(s,t)
ans = 1×2 table
s t ___________ ___________ 1×20 double 1×20 double

Davide Masiello
Davide Masiello 2022년 12월 12일
편집: Davide Masiello 2022년 12월 12일
There are a couple of errors in your code.
First, the way you define the array t.
Second, for array operations, use the dot notation.
Third, no need to specify the s dependence on t.
r = 9;
omega = 100;
b = 14;
t = linspace(0,0.01,20)';
s = r*cos(2*pi*omega*t)+sqrt(b^2-(r^2)*sin(2*pi*omega*t).^2);
table(s,t)
ans = 20×2 table
s t ______ __________ 23 0 22.204 0.00052632 19.965 0.0010526 16.722 0.0015789 13.158 0.0021053 10.006 0.0026316 7.7015 0.0031579 6.2396 0.0036842 5.4133 0.0042105 5.0442 0.0047368 5.0442 0.0052632 5.4133 0.0057895 6.2396 0.0063158 7.7015 0.0068421 10.006 0.0073684 13.158 0.0078947
It seems like you might be new to Matlab, so I suggest reading some of the basic documentation. e.g.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by