Question: 2.3 MATLAB Function, and ERRORS! t-1 Another way to calculate sin(x) is using the infinite Taylor series: sin(x)- >(-1 (2k-1) Let's define the approximation sin(x)

 2.3 MATLAB Function, and ERRORS! t-1 Another way to calculate sin(x)

2.3 MATLAB Function, and ERRORS! t-1 Another way to calculate sin(x) is using the infinite Taylor series: sin(x)- >(-1 (2k-1) Let's define the approximation sin(x) as the sum of the first N terms from k-1 up to some k = N. That is, sinN(x)->(-1 So, sin,(x)-x, sin2(x)-x - x3/6, sin (x)-x -x3/6+x5/120, etc (a) Develop a function Y -sinN (x, Nmax) that takes in a scalar x, an integer Nmax, and (2k-1) outputs a (1 x Nmax) row vector where the Nth element in is equal to sinN(x) In other words, the first element of Y will be the approximation for sin(x) with just one term, the second element will use two terms, the third element will use three terms, etc. That mean:s you'd expect the elements in the vector Y from left-to-right to get closer and closer to the real value of sin(x) First, do you understand what you're trying to do? If not, take Nmax- 3, x /4, and use your calculator to create the 1x3 output by hand Y-[sin1x) sin2x) sin3(x), and prove to yourself that each term in Y is getting closer to the exact analytic solution sin(t/4)sqrt(2) (Don't hand this in, this is just to help you "see" what to do before you start coding.) (b) Look in this Carmen HW2 directory for the script HW2_3.m, also written out below. This script uses your new function sinN.m to approximate sin(x) for x-x/4 Input value s for sinN(x,Nmax) & YOU create this function yourself AbsErrabs (sin (x) -Y); PctAbsErAbsErr/sin (x) 100; Absolute value of error Absolute value of percent error % TOP plot f error vs N subplot (211) plot ([1 :Nmax],PtAbsErr,-o') title( Percent Error in sin N(x) with N') xlabel ('N) ylabel (' Errorl') subplot (212) plot ([1 :Nmax],log10 (PctAbsErr),)BOTTOM plot of title('log of Fercent Error in sin N(x) with N) xlabel('N) ylabel ('log_1_0( Error)') log (serror) vs N Notice that this script (i) uses your function to calculate better and better approximations for siny(t/4) for N up to 10, (ii) calculates the absolute value of the error and percent error compared to the "exact" solution using MATLAB's built-in sin(x) command, (ii) plots the percent error in the top plot, and log1o of percent error in the bottom plot, against N You should see the error going down as N gets bigger! In fact, I see AbsErr is exactly zero before N = 10" But doesn't that seem to violate common sense since there's still lots of terms beyond N 10 left to calculate? Think about it and I'll ask you in class next week. HW2.3: Please submit all the following ON-LINE (through Carmen, i.e. nothing submitted on paper) . Your documented function sinN.m from part (a) Your labeled plot (with two "subplots" on it from part (b)) called PDF2_3.pdf . In the comment field, enter the lowest value N where AbsErr goes exactly to zero

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!