how can i plot this sin wave as shown

4 ビュー (過去 30 日間)
Chad Gray
Chad Gray 2016 年 3 月 20 日
編集済み: Chad Gray 2016 年 3 月 20 日
hello everyone and thanks in advance for help, i'm asked to plot this sin wave shown in the image below and i have to only get the first wave with the points on the graph. Now i have used this code in order to do so where i put
t = 0:pi/50:2;
s = sin(2*pi*t);
plot(t,s)
but when i get the plot i always get two waves and i must get only one with the specified points. help anyone and ty.

採用された回答

Image Analyst
Image Analyst 2016 年 3 月 20 日
編集済み: Image Analyst 2016 年 3 月 20 日
Very close, but the formula for a sine wave is Amplitude * sin(2*pi*x / period). If you do that, what do you get?
period = ??????; % You do this.
t = linspace(-1, 3, 500);
s = sin(2 * pi * t / period); % Now using the proper formula
plot(t,s, 'b-');
% Fancy up the graph, just for fun...
grid on;
% Plot Y axis
line([0,0], ylim, 'Color', 'k', 'LineWidth', 2);
% Plot x axis
line(xlim, [0,0], 'Color', 'k', 'LineWidth', 2);
yLabel('s', 'FontSize', 20);
xLabel('t', 'FontSize', 20);
  1 件のコメント
Chad Gray
Chad Gray 2016 年 3 月 20 日
編集済み: Chad Gray 2016 年 3 月 20 日
ty very much it finally worked

サインインしてコメントする。

その他の回答 (1 件)

John D'Errico
John D'Errico 2016 年 3 月 20 日
編集済み: John D'Errico 2016 年 3 月 20 日
What is the period of the sine function? Answer: 2*pi
If t goes from 0 to 2, then how many periods do you expect to see? Remember, your function is sin(2*pi*t). Hint: 2*pi*2 = 4*pi.
Therefore one should EXPECT to see 2 periods. Why are you surprised?
By the way,
t = 0:pi/50:2
may be a poor choice, if you really wanted to go all the way out to t==2. The last point will fall short, since you used an increment of pi/50.
A better choice may have been to use linspace.
  1 件のコメント
Chad Gray
Chad Gray 2016 年 3 月 20 日
ty for help and i'm new to this matlab stuff only started learning matlab about 1 month ago so i'm having some troubles and thanks for the advice

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by