Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help with Problem 4 (Matlab Coding) Recall that the truncated Taylor series of a function f(x) about a point zo is given by: 7
Need help with Problem 4 (Matlab Coding)
Recall that the truncated Taylor series of a function f(x) about a point zo is given by: 7 Tn (2) = f(k) (20) k! (2 - 204 (1) k=0 For f(x) = log x the task of evaluating (1) about 20 = 1 yields T (2) = (-1)4-1 k -(- 1) (2) k=1 Problem 1 (a) Derive a Taylor series with n+1 terms and the associated truncation error for the function log(x) - 2+1 f(x) = (2-1) (3) Your expression for the Taylor series should be general, similar to the series for log(x) (see LabiA for examples of such computations). Note that this is actually much easier if you start with the Taylor series for log 2 and write out the first few terms explicitly starting with log(x) = (x - 1) +..., rather than starting from the definition above. (b) Construct an expression that bounds the truncation error, assuming n > 2, for a given value of 2. See especially the review material and examples related to Taylor's series with remainder in Section 0.5 of the Text by Sauer. Problem 2 (a) Modify an M-file for Taylor Series from Lab1A (e.g. for exp(x) without using Horner) to compute and plot the Taylor series and f(x) from problem 1 above (an M-file is expected to be handed in for this part with filename lab1bP2.m). A couple of implementation hints that may be useful: (0) Note that the loop does not have to start with 1. (ii) Note that the first term in the series is now -1/2 rather than 0 so you will need to 1 Problem 4 In this problem we want to create a matlab function that can evaluate f(x) to a given accuracy for any value of x. (a) Create a new m-File, called myfofx.m. Unlike our previous script files, we would like this to be a function, just like log(x) or sin(x) that returns a number. i.e. we would like to be able to use the function in commands like: y-myfofx(1.001) or plot (x,myfofx (x)) To do this, we need to put the line function (fx]-myfofx(x) 2 as the first non-commented line in the m-file. Then, fx will be the variable that we will use in the m-file that, at the end of the calculation, contains our answer. Note that unlike previous cases where x and T were scalars you will not need to set the value of x as it will be passed to the function. In this case, just return the value of the n = 8 Taylor series (i.e. replace the fprintf statement with fx=T before the return). Test the function by evaluating the result on the command line for myfofx(1) and myfofx(2). Make sure you are getting the correct result before proceeding. (b) If we are close to r = 1 our previous results suggest that it would be better to use the Taylor series. However, if we are far away from 2 = 1, the accuracy of our Taylor series starts to degrade due to truncation error. Use an if-else construct to modify your function to use the Taylor series when 1 10-6 2, for a given value of 2. See especially the review material and examples related to Taylor's series with remainder in Section 0.5 of the Text by Sauer. Problem 2 (a) Modify an M-file for Taylor Series from Lab1A (e.g. for exp(x) without using Horner) to compute and plot the Taylor series and f(x) from problem 1 above (an M-file is expected to be handed in for this part with filename lab1bP2.m). A couple of implementation hints that may be useful: (0) Note that the loop does not have to start with 1. (ii) Note that the first term in the series is now -1/2 rather than 0 so you will need to 1 Problem 4 In this problem we want to create a matlab function that can evaluate f(x) to a given accuracy for any value of x. (a) Create a new m-File, called myfofx.m. Unlike our previous script files, we would like this to be a function, just like log(x) or sin(x) that returns a number. i.e. we would like to be able to use the function in commands like: y-myfofx(1.001) or plot (x,myfofx (x)) To do this, we need to put the line function (fx]-myfofx(x) 2 as the first non-commented line in the m-file. Then, fx will be the variable that we will use in the m-file that, at the end of the calculation, contains our answer. Note that unlike previous cases where x and T were scalars you will not need to set the value of x as it will be passed to the function. In this case, just return the value of the n = 8 Taylor series (i.e. replace the fprintf statement with fx=T before the return). Test the function by evaluating the result on the command line for myfofx(1) and myfofx(2). Make sure you are getting the correct result before proceeding. (b) If we are close to r = 1 our previous results suggest that it would be better to use the Taylor series. However, if we are far away from 2 = 1, the accuracy of our Taylor series starts to degrade due to truncation error. Use an if-else construct to modify your function to use the Taylor series when 1 10-6Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started