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

In this exercise you will write 3 functions. The first and the second will calculate 2 different types of 

Write the code in MATLAB.

Please write the code in MATLAB. %% Part ( ) ) function ecompare (err) % here err is a vector nA= []; % will (1-1)^n; approx=1/deno; % approximated value of el as the difference is more than equal to err n=n+1; 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

1 Expert Approved Answer
Step: 1 Unlock

Part C function ecompareerr here err is a vector nA will contain values of n for Part A for each err ... View full answer

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 Mathematics Questions!