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

5 views (last 30 days)
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.

Answers (1)

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

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!