Cody

Problem 42807. Approximate e

Solution 2553378

Submitted on 14 Jun 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
a = 1; n = 1; f_correct = a*exp(n); assert(abs(approx_e(a,n)-f_correct)<.001)

2   Fail
a = 2^18; n = 0; f_correct = a*exp(n); assert(abs(approx_e(a,n)-f_correct)<.001)

Error using odearguments (line 83) The last entry in tspan must be different from the first entry. Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); Error in approx_e (line 2) [t,y] = ode45(@eeqn,[0 n],a); Error in Test2 (line 4) assert(abs(approx_e(a,n)-f_correct)<.001)

3   Pass
a = pi; n = pi; f_correct = a*exp(n); assert(abs(approx_e(a,n)-f_correct)<.001)

4   Fail
a = -exp(1); n = exp(2); f_correct = a*exp(n); assert(abs(approx_e(a,n)-f_correct)<.001)

Assertion failed.

5   Pass
filetext = fileread('approx_e.m'); assert(isempty(strfind(filetext,'exp'))) assert(isempty(strfind(filetext,'str'))) assert(isempty(strfind(filetext,'cat'))) assert(isempty(strfind(filetext,'feval'))) assert(all(cellfun(@(z)str2num(z)==round(str2num(z)),regexp(filetext,'[0123456789.]+','match')))) assert(isempty(regexp(filetext,'\d+e')))