how to plot sine wave without built in function ?

12 次查看(过去 30 天)
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 个评论
Guillaume
Guillaume 2015-12-7
Probably not the answer you want, but conforms exactly to your request:
sine = @(x) cos(pi/2 - x);
Shaheer Ali
Shaheer Ali 2015-12-8
thankyou but i want o plot it without the builtin sine cosine functions

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2015-12-7
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 个评论
Shaheer Ali
Shaheer Ali 2015-12-8
umm im still a beginner so can you please wxplain it a little and specify how to plot using this .. please .. thankyou !
Star Strider
Star Strider 2015-12-8
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
similarly how to plot 2 different sine waves with a phse difference?

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by