how to plot sine wave without built in function ?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shaheer Ali
le 7 Déc 2015
Réponse apportée : Thomas Alex
le 12 Jan 2020
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 commentaires
Guillaume
le 7 Déc 2015
Probably not the answer you want, but conforms exactly to your request:
sine = @(x) cos(pi/2 - x);
Réponse acceptée
Star Strider
le 7 Déc 2015
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 commentaires
Star Strider
le 8 Déc 2015
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
Plus de réponses (1)
Thomas Alex
le 12 Jan 2020
similarly how to plot 2 different sine waves with a phse difference?
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!