Hi !!! what is wrong in my code ??

give me code of s(t) = cos(2*Π*100*t) + cos(2*Π*200*t).
t = 0:.01:1 % independent (time) variable
A = 8; % amplitude
f_1 = 2; % create a 2 Hz sine wave lasting 1 sec
s_1 = A*sin(2*pi*f_1*t);
f_2 = 4; % create a 4 Hz sine wave lasting 1 sec
s_2 = A*sin(2*pi*f_2*t);
%plot the 2 Hz sine wave in the top panel
subplot(3,1,1) ,plot(t, s_1)
title('2 Hz sine wave')
ylabel('Amplitude')
%plot the 4 Hz sine wave in the middle panel
subplot(3,1,2) , plot(t, s_2)
title('4 Hz sine wave')
ylabel('Amplitude')
%plot the summed sine waves in the bottom panel
subplot(3,1,3) , plot(t, s_1+s_2)
title('Summed sine waves')
ylabel('Amplitude')
xlabel('Time (s)')

回答 (2 件)

Star Strider
Star Strider 2020 年 12 月 13 日

0 投票

It appears to run without error and gives what I consider the appropriate result.
What problems are you having with it?
If you want to plot:
give me code of s(t) = cos(2*Π*100*t) + cos(2*Π*200*t).
instead, make the appropriate substitutions for ‘A’, ‘f_1’, and ‘f_2’ in the code you posted, and change the sin calls to cos calls.

7 件のコメント

Titu talukder
Titu talukder 2020 年 12 月 13 日
t = 0:.01:1 % independent (time) variable
A = 8; % amplitude
f_1 = 2; % create a 2 Hz sine wave lasting 1 sec
c_1 = f1*cos(2*pi*f_1*t);
f_2 = 4; % create a 4 Hz sine wave lasting 1 sec
c_2 = f2*cos(2*pi*f_2*t);
%plot the 2 Hz cos wave in the top panel
subplot(3,1,1) ,plot(t, c_1)
title('2 Hz cos wave')
ylabel('Amplitude')
%plot the 4 Hz cos wave in the middle panel
subplot(3,1,2) , plot(t, c_2)
title('4 Hz cos wave')
ylabel('Amplitude')
%plot the summed sine waves in the bottom panel
subplot(3,1,3) , plot(t, c_1+c_2)
title('Summed cos waves')
ylabel('Amplitude')
xlabel('Time (s)')
error 1 : Undefined function or variable 'x'.
Error in Untitled6 (line 8)
plot(t,x);
error2: Undefined function or variable 'f1'.
Error in control1lab (line 4)
s_1 = f1*cos(2*pi*f_1*t);
Star Strider
Star Strider 2020 年 12 月 13 日
Note that ‘A’ is the amplitude and ‘f_1’ and ‘f_2’ are the frequencies.
Look at ‘c_1’ and ‘c_2’ and make the appropriate substitutions, using the information in ‘s(t)’.
Titu talukder
Titu talukder 2020 年 12 月 13 日
if you dont mind , can you write the whole code here ? plz
Star Strider
Star Strider 2020 年 12 月 13 日
Since this appears to be homework, the policy on MATLAB Answers is not to provide working code for homework problems.
The code you were given is in the context of:
Amplitude * cos(2*pi*Frequency*t)
for each term.
I will let you take it from there.
Titu talukder
Titu talukder 2020 年 12 月 13 日
you can send me in an email , plz
titutalukder11978@gmail.com
Star Strider
Star Strider 2020 年 12 月 13 日
I have given you all the help I can possibly give without writing the code for you.
Please re-read what I wrote and experiment using the hints I have provided.
Star Strider
Star Strider 2020 年 12 月 13 日
That code should do what you want. It really was not that difficult!

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

Titu talukder
Titu talukder 2020 年 12 月 13 日

0 投票

t = 0:.01:1;
A = 1;
fm1 = 100;
s1 = A*cos(2*pi*fm1*t);
fm2 = 200;
s2 = A*cos(2*pi*fm2*t);
subplot(3,1,1) ,plot(t, s1);
title('cos(2*pi*100*t)');
ylabel('Amplitude');
subplot(3,1,2) , plot(t, s2);
title('cos(2*pi*200*t)');
ylabel('Amplitude');
subplot(3,1,3);
plot(t, s1+s2);
title('S(t)');
ylabel('Amplitude');
xlabel('Time (s)');

カテゴリ

ヘルプ センター および File ExchangePerformance and Memory についてさらに検索

質問済み:

2020 年 12 月 13 日

コメント済み:

2020 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by