How to plot the Taylor Series expansion of sin²(x) in MATLAB
11 次查看(过去 30 天)
显示 更早的评论
The Taylor Series expansion for
is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1523316/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1523321/image.png)
2 个评论
Steven Lord
2023-10-27
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Sulaymon Eshkabilov
2023-10-27
It is a homework assignment. Show what you have done so far and where you've got stuck, then MATLAB community people will give you some hints and directions.
As of now, you can start working on how to enter variables, perform calcs and plot the calculated values.
Then you can work on these functions: syms; taylor(), plot(), fplot(), legend(), xlabel(), etc.
All the best.
回答(2 个)
Sam Chak
2023-10-27
Hi @Abdulazziz
I believe you when you say you don't know how to plot this in MATLAB. However, I don't understand the logical reasoning behind your attempts when you have no knowledge of the code. Perhaps, I should interpret the message using fuzzy logic, where intermediate truth values between true and false are allowed, such as 70% true and 30% false.
In any case, I'll show you a simple example, and you can learn by example.
ss = 0.0001; % step size
x = -0.75:ss:0.75; % plot interval
y = 1./(1 - x) - 1; % the function, f(x)
y1 = x; % 1 term
y2 = x + x.^2; % 2 terms
y3 = x + x.^2 + x.^3; % 3 terms
y4 = x + x.^2 + x.^3 + x.^4; % 4 terms
y5 = x + x.^2 + x.^3 + x.^4 + x.^5; % 5 terms
plot(x, y, x, y1, x, y2, x, y3, x, y4, x, y5)
legend('y(x)', '1-term', '2-term', '3-term', '4-term', '5-term', 'location', 'NW')
grid on
title('Give a name to this Graph')
xlabel('Display label on this horizontal axis')
ylabel('Display label on this vertical axis')
2 个评论
Sam Chak
2023-10-27
The question is shown here so that other people can 'easily' read the problem without clicking on the jpg image.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1523246/image.jpeg)
Sam Chak
2023-10-27
Hi @Abdulazziz
Your question has magically disappeared. But fret not; you can refer to the explanation here on how to count the terms in the Taylor Series expansion. It will contribute meaningfully to the community by helping others understand how to plot the Taylor Series expansion, whether they are students or professors.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1523296/image.png)
Sulaymon Eshkabilov
2023-10-27
编辑:Sulaymon Eshkabilov
2023-10-27
There is a fcn called taylor() which can be used for your simulations as well intead of typing the whole formulation of polynomials, e.g.:
help taylor % Explains what this fcn does and how to use it
syms x
NEAR_what = pi; % 'ExpansionPoint': Expand around what value of x to find a polynomial approximation
N_terms3 = 3; % 'Order': How many terms to be used
COSINE_T1 = taylor(cos(x), x,'ExpansionPoint', NEAR_what, 'Order', N_terms3)
fplot(@(x)cos(x), [0, 2*pi])
hold on
fplot(COSINE_T1, [0, 2*pi])
xlabel('x')
ylabel('f(x)')
legend
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!