Create an input array from -1*pi to 1*pi

% Create an input array from -1*pi to 1*pi
t=[3 4 5 6 7 8 9];
% Calculate |sin(t)|
x=abs(sin(t));
%plot result
plot(t,x);

回答(1 个)

% Create an input array from -1*pi to 1*pi
t=-pi:pi;
% Calculate |sin(t)|
x=abs(sin(t));
%plot result
plot(t,x);

5 个评论

And with a finer grid:
t = -pi:0.01:pi; % But this does not match the endpoint exactly!
t = linspace(-pi, pi, 200); % See: doc linpsace
Thank you, for my lerning and understanding, if the -1*pi to 1*pi was changed to other numbers say -3 and 3 would t=-3pi:3pi; and where does the t=[3 4 5 6 7 8 9]; factor in.
3 4 5 etc does not fit at all.
linspace(-3*pi,3*pi)
Thanks, what about if it was t=[0 1 2 3 4 5 6]; what is the "t" refering to.
If you set
t=[0 1 2 3 4 5 6];
x=abs(sin(t));
plot(t,x)
MATLAB takes the point (0,abs(sin(0))), (1,abs(sin(1))),...,(6,abs(sin(6))) and connects them in this order by straight lines in the plot.
Same for any array t that you define in advance.

请先登录,再进行评论。

产品

版本

R2022a

标签

提问:

2022-5-23

评论:

2022-5-25

Community Treasure Hunt

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

Start Hunting!

Translated by