I have been working on writing g a script file that will:(adsbygoogle = window.adsbygoogle || []).push({});

- Calculate f(x)=5sin(3x) using the Taylor series with the number of terms n=2, 5, 50, without using the built-in sum function.
- Plot the three approximations along with the exact function for x=[-2π 2π].
- Plot the relative true error for each of the approximations
- Calculate the value of sin(x) and the error for x=π and x=3π/2 for each of the approximations
- How many terms are necessary for an error E<.000001?

I have been able to get as far as the third part of the question, any advice, tips or pointers are greatly appreciated!

I pasted the script I have so far bellow:

clear, clc, close all

%Define the limits, the original function and the Taylor series.

syms x

a = -2*pi:2*pi;

g = (5*sin(3*x));

T_2 = taylor(g, 'Order', 2);

T_5 = taylor(g, 'Order', 5);

T_50 = taylor(g, 'Order', 50);

z = (5*sin(3*a));

%plot the original function and the three Taylor series.

fg=figure;

ax=axes;

ez1=plot(a,z, 'r--');

hold on

ez2=ezplot(char(T_2),[-2*pi, 2*pi]);

ez3=ezplot(char(T_5),[-2*pi, 2*pi]);

ez4=ezplot(char(T_50),[-2*pi, 2*pi]);

legend('5sin(3x)','T2','T5','T50')

set(ez2, 'color', [0 1 0])

set(ez3, 'color', [0 0 1])

set(ez4, 'color', [1 0 1])

title(ax,['Graph of 5sin(3x) and taylor expansions T2, T5 and T50'])

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab taylor series script

Loading...

Similar Threads for Matlab taylor series |
---|

MATLAB MATLAB: forces acting on an object |

MATLAB Matlab histogram |

MATLAB Sovling Bernoulli's differential equation in matlab? |

MATLAB Matlab-like software |

MATLAB Matlab data into bins |

**Physics Forums | Science Articles, Homework Help, Discussion**