how to plot sine wave without built in function ?

Hi.. um i wanted to ask a small question .. um a beginner in Matlab so .. i wanted to know if there's a way to create a sine wave without the sine function .. ? waiting for your reply

댓글 수: 3

Adam
Adam 2015년 12월 7일
Obviously you could estimate one, but why would you want to?
Probably not the answer you want, but conforms exactly to your request:
sine = @(x) cos(pi/2 - x);
thankyou but i want o plot it without the builtin sine cosine functions

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

 채택된 답변

Star Strider
Star Strider 2015년 12월 7일

0 개 추천

I don’t know why you would want to, but this works with reasonably accuracy:
sine = @(x) sum((x.^[1:2:18]) .* -((-1).^[1:9]) ./ factorial([1:2:18]));

댓글 수: 2

umm im still a beginner so can you please wxplain it a little and specify how to plot using this .. please .. thankyou !
My pleasure!
To plot it, first define a range for the angle, then use the function on that range. I wrote it quickly, so it doesn’t take vector arguments and the loop is necessary:
sine = @(x) sum((x.^[1:2:18]) .* -((-1).^[1:9]) ./ factorial([1:2:18]));
angl = linspace(-2*pi, 2*pi, 500);
for k1 = 1:length(angl)
sineval(k1) = sine(angl(k1));
end
figure(1)
plot(angl, sineval)
grid

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

추가 답변 (1개)

Thomas Alex
Thomas Alex 2020년 1월 12일

0 개 추천

similarly how to plot 2 different sine waves with a phse difference?

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

태그

질문:

2015년 12월 7일

답변:

2020년 1월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by