Creating a graph of sin(x) and the taylor series for its approximation
7 次查看(过去 30 天)
显示 更早的评论
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.
1 个评论
回答(1 个)
Shubham Gupta
2019-9-24
Change the line
x=linspace(0,100,2*pi);
by
x=linspace(0,2*pi,100);
I hope it helps !
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!