필터 지우기
필터 지우기

where am i going wrong? i get errors when i multiply the functions

조회 수: 3 (최근 30일)
Emmanuel
Emmanuel 2014년 3월 13일
댓글: Emmanuel 2014년 3월 13일
Plot the following function from t=1 to t=2, sin(2*pi*3*t)*sin(2*pi*15*t). Label both axes, and give the plot a title. so this is the code i wrote but i keep get error. i am new at using matlab. I would like to know what i am doing wrong.
t= (1:1.1,2); x= sin(2*pi*3*t) y= sin(2*pi*15*t) c= (x*y)

답변 (2개)

nl2605
nl2605 2014년 3월 13일
for t = 1:2
x(t) = sin(2*pi*3*t);
y(t) = sin(2*pi*15*t);
c(t) = x(t).* y(t);
end
This should work
  댓글 수: 3
Chris C
Chris C 2014년 3월 13일
The difference is the ".*" part when you multiply the two variables. The period tells matlab that you want to multiply each array element by the corresponding element in the other array instead of performing matrix multiplication.
Emmanuel
Emmanuel 2014년 3월 13일
thanks. that was quite helpful the coresponding plot matches my manually generated graph.

댓글을 달려면 로그인하십시오.


Joseph Cheng
Joseph Cheng 2014년 3월 13일
couple of things with your line.
  1. for the t=1:1.1:2 are you attempting to get t=1 to 2 with increments of .1?if so it should look more like t=1:.1:2;
  2. you should have a ";" after each function execution or atleast a "," to separate what you are doing. if you don't it will try to execute
t= (1:.1:2); x= sin(2*pi*3*t);y= sin(2*pi*15*t);c= (x.*y) as one single command.
3. the c = (x*y) will also give an error when it gets that far due to the matrix multiplication dimension mismatch. you'll have to use the element-by-element multiplication ".*". See element-by-element multiplication finally your line should look like
t= (1:.1:2); x= sin(2*pi*3*t);y= sin(2*pi*15*t);c= (x.*y)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by