Cody

Solution 835688

Submitted on 22 Feb 2016 by Peng Liu
  • Size: 20
  • This is the leading solution.
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
fh=@sin; x0=pi/4; h=1e-4; y_correct = 0.707106780007960; tol=1e-4; assert(abs(diffquot(fh,x0,h)-y_correct)<tol);

y = 0.7071

2   Pass
fh=@(x) x^2+1; x0=2; h=1e-4; y_correct = 4.000000 tol=1e-4; assert(abs(diffquot(fh,x0,h)-y_correct)<tol);

y_correct = 4 y = 4

3   Pass
fh=@(x) 3*sqrt(x^2+1); x0=5; h=1e-4; y_correct = 2.941742027049443 tol=1e-4; assert(abs(diffquot(fh,x0,h)-y_correct)<tol);

y_correct = 2.9417 y = 2.9417