Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. (60 pts) Write a Matlab function to approximate the inverse of the mathematical constant e (natural exponential constant) as the following: e =(-)
1. (60 pts) Write a Matlab function to approximate the inverse of the mathematical constant e (natural exponential constant) as the following: e =(-)" The function will take one input, n, which is interpreted as follows: (a) If n is less or equal than zero, the function should provide an error message to the user that this is not allowed, and then exit; (b) If n >= 1, the function should evaluate the above equation using round (n) as the input, i.e., replace n by round (n). (c) If n < 1, for example, 0.01, then the input will be interpreted as the error threshold, thresh. The function should loop through values of n starting from integer 1 and increment by 1 until the absolute difference between the approximation and the actual value is less than the given thresh. (hint, the value of e can be found by using exp (1) in Matlab). In the last two cases, the function should print out the built-in value of and the approximation to 4 decimal places (hint: fprintf in Matlab, use specifier 5.4f '). In case (c), also print out the value of n required for such accuracy. The output of the function should be the inverse of the constant, e. You are free to name your own function. (d) Call your function in the command window several times, with each of the above test conditions considered. Then put the display messages to your function on the top as comments. ("%')
Step 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