Creating a graph of sin(x) and the taylor series for its approximation

8 visualizaciones (últimos 30 días)
Hami the Penguin
Hami the Penguin el 24 de Sept. de 2019
Comentada: miaofen li el 24 de Sept. de 2019
Hello,
I am having problem to solve a question given from my engineering class. The question asks to plot a graph of y1=sin(x), y2=x, and y3= x - x^3 / 3! + x^5 / 5!. This is the script which I coded:
clear all;
clc;
x=linspace(0,100,2*pi);
y1=sin(x);
y2=x;
y3=x-(x.^3)/factorial(3)+(x.^5)/factorial(5);
plot(x,y1,'-r')
hold on;
plot(x,y2,'--b')
hold on;
plot(x,y3,':g')
axis([0,5,-1,5])
xlabel('x')
ylabel('Approximations of sin(x)')
title('expanding Sinusoids')
grid on
legend({'sin(x)','x','taylor series'},'location','northwest')
And the graph looks completely wrong:
Can someone help me find my error and fix it?
Thank you.

Respuestas (1)

Shubham Gupta
Shubham Gupta el 24 de Sept. de 2019
Change the line
x=linspace(0,100,2*pi);
by
x=linspace(0,2*pi,100);
I hope it helps !

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by