Cody

# Problem 231. Differential equations I

Solution 1739442

Submitted on 28 Feb 2019
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   Fail
f = @(x) -x; tf =1; y0 =1; assert(abs(deqnsolve(f,y0,tf)-exp(-1)) < 1e-5)

Error using odearguments (line 113) Inputs must be floats, namely single or double. Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); Error in deqnsolve (line 3) [t,y] = ode45(@(x,y) f,tspan,y0); Error in Test1 (line 4) assert(abs(deqnsolve(f,y0,tf)-exp(-1)) < 1e-5)

2   Fail
f = @sin; tf =1; y0 =1/2; assert(abs(deqnsolve(f,y0,tf)-2*acot(exp(-1)*cot(1/4))) < 1e-5)

Error using odearguments (line 113) Inputs must be floats, namely single or double. Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); Error in deqnsolve (line 3) [t,y] = ode45(@(x,y) f,tspan,y0); Error in Test2 (line 4) assert(abs(deqnsolve(f,y0,tf)-2*acot(exp(-1)*cot(1/4))) < 1e-5)

3   Fail
f = @(x) 1/(x+1); tf =6; y0 =1; assert(abs(deqnsolve(f,y0,tf)-3) < 1e-5)

Error using odearguments (line 113) Inputs must be floats, namely single or double. Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); Error in deqnsolve (line 3) [t,y] = ode45(@(x,y) f,tspan,y0); Error in Test3 (line 4) assert(abs(deqnsolve(f,y0,tf)-3) < 1e-5)

4   Fail
a = rand*0.9; f = @(x) x-a*x^2; tf = rand+1.5; y0=1; assert(abs(deqnsolve(f,y0,tf)-exp(tf)/(1-a+a*exp(tf))) < 1e-5)

Error using odearguments (line 113) Inputs must be floats, namely single or double. Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); Error in deqnsolve (line 3) [t,y] = ode45(@(x,y) f,tspan,y0); Error in Test4 (line 5) assert(abs(deqnsolve(f,y0,tf)-exp(tf)/(1-a+a*exp(tf))) < 1e-5)