Taylor Series figure problem
이전 댓글 표시
Consider the following expression:
f(x)= x^2 sin(x)+e^-x * cos^2 (x)
Plot varying 'x' from '-π' to '+π' for 100 points.
Using Taylor's series expansion for of degree 4, plot the graph with the above graph using hold on feature for same range of x.
Add Taylor series of degrees 7 and 10 to the same plot.
Compare the results. In the graph, add legend, title, axis titles. Add different line style, markers, colors. Choose appropriate font size for the graph.
this is my code and I got two figures but one of them is not the true solution which is the first figure so can you please help?
xx= linspace(-pi,pi, 100);
syms x
fx=(x*x^2)*sin(x*x)+exp(-x*x)*(cos(x*x)^2);
figure(1)
fplot(xx,fx, 'linewidth' ,2)
title('Original Signal')
xlabel('x')
ylabel('f(x)')
f= (x^2)*sin(x)+exp(-x)*(cos(x)^2);
T4 = taylor(f,x, 'Order',4);
figure (2)
fplot(T4,[-pi pi],'--')
hold on;
T7 = taylor(f,x,'Order', 7);
fplot(T7,[-pi pi],'-o')
T10 = taylor(f,x, 'Order', 10);
fplot(T10,[-pi pi],'-')
legend('Degree = 4','Degree = 7', 'Degree = 10')
xlabel('x')
ylabel('f(x)')
title('Taylor Series Approximation')
채택된 답변
추가 답변 (1개)
Walter Roberson
2023년 2월 11일
편집: Walter Roberson
2023년 2월 11일
Your fplot syntax was wrong.
xx= linspace(-pi,pi, 100);
syms x
fx=(x*x^2)*sin(x*x)+exp(-x*x)*(cos(x*x)^2);
figure(1)
fplot(fx, [-pi pi], 'linewidth' ,2)
title('Original Signal')
xlabel('x')
ylabel('f(x)')
f= (x^2)*sin(x)+exp(-x)*(cos(x)^2);
T4 = taylor(f,x, 'Order',4);
figure (2)
fplot(fx, [-pi pi], 'linewidth' ,2)
hold on
fplot(T4,[-pi pi],'--')
T7 = taylor(f,x,'Order', 7);
fplot(T7,[-pi pi],'-o')
T10 = taylor(f,x, 'Order', 10);
fplot(T10,[-pi pi],'-')
legend({'origina', 'Degree = 4','Degree = 7', 'Degree = 10'})
xlabel('x')
ylabel('f(x)')
title('Taylor Series Approximation')
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





