Question: Write the code in MATLAB. This is the code that is already given by 1 of the experts, could you please change the code
Write the code in MATLAB.
This is the code that is already given by 1 of the experts, could you please change the code a bit for me if possible?
In this exercise you will write 3 functions. The first and the second will calculate 2 different types of approximation to the number e (Euler's number). The third function will provide a comparison between the 2 approximations. [Hint: In matlab the value of e can be obtained using exp (1)] Part A The inverse of e can be approximated as follows: 4-(-4) Write a function myevalueA that receives as input a value err. The function should calculate an approximation to e (using the formula above) such that the difference between the approximation and the actual value of e is smaller than err. The function will then return the corresponding value of n. Part B The constant e can also be approximated by the following expression: i=0 where i! indicates the factorial of i. Write a function myevalueB that receives as input a value err. The function should calculate an approximation to e (using the formula above) such that the difference between the approximation and the actual value of e is smaller than err. The function will then return the corresponding value of n. Part C Write a function ecompare that will receives as input a vector containing 5 different values of err and will run both myevalueA and myevalueB using these values. The function will then create a plot showing the number of iterations required by the 2 different functions vs the values of err. Note that you will need to provide a way to distinguish between the points obtained with the 2 different methods so that the plot can be used to assess the speed of convergence of the approximations.
Step by Step Solution
3.44 Rating (170 Votes )
There are 3 Steps involved in it
Part C function ecompareerr here err is a vector nA will contain values of n for Part A for each err ... View full answer
Get step-by-step solutions from verified subject matter experts
