Math 112: MATLAB Assignment 2
► TAYLOR SERIES AND POLYNOMIALS ► Due Date: April 20, 2018
The sample program below calculates 2nd and 4th degree Taylor polynomials for the function
about the point
The polynomials are plotted, together with the function, over the interval
Contents
Sample program
Lines beginning with a percent sign (%) are comments construct Taylor polynomials.
figure(1);clf; %open figure one and clear any plots x=[-1: .01:1]; y=(1+x.^2).^(-1); %the function P2=1-x.^2; %the second-order Taylor polynomial (calculated by hand) P4=1-x.^2+x.^4; %the 4th order Taylor polynomial % annotating the graph is always important figure(1);clf; %open and clear the 1st figure plot(x,y,x,P2,'--',x,P4,'-.') legend('1/(1+x^2)','P_2','P_4') xlabel('x') title('The function and the 2^{nd} and 4^{th} order Taylor Polynomials') figure(2);clf; %open and clear the 2nd figure plot(x,abs(y-P2),x,abs(y-P4),'--') % abs is the absolute value legend('|1/(1+x^2)-P_2|','|1/(1+x^2)-P_4|') xlabel('x') title('Errors in the two Taylor Polynomials') % Program output:
New Matlab Ideas
the Legend command generates a legend for your graph. If there are two curves in your graph, the legend command should consist of two strings (defined using single quotation marks). Note that the underscore ('_') is used to make subscripts and the caret ('^') is used to make superscripts. if you want to create a superscript with more than one character in it, enclose the superscripted text in braces ('{}')
For example, to type
you would use the string 'e^{ix}'.
Variables used
- x, y: the independent and dependent variables
- P2, P4: the 2nd and 4th order Taylor polynomials
Your Assignment
After running the above example, do the following to hand in: (Consult the MATLAB TA's if you have any questions.)
Calculate the 2nd and 3rd degree Taylor polynomials for the function
about the point
Plot these polynomials and the function on the interval
Please be sure to turn in your hand calculation as well as your code and your clearly labeled plot.