Cody

# Problem 1289. Evaluating continued fractions

Solution 227667

Submitted on 6 Apr 2013 by @bmtran (Bryant Tran)
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
%% c=ones(1,40); x=(1+sqrt(5))/2; y=contfrac(c); assert(abs(y-x)<1e-15)

[Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14]

2   Pass
%% c=[3 7 15 1 292 1 1 1 2 1 3 1 14]; x=pi; y=contfrac(c); assert(abs(y-x)<1e-15)

[Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14]

3   Pass
%% c=[3 7 15 1]; x=355/113; y=contfrac(c); assert(abs(y-x)<1e-15)

[Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14]

4   Pass
%% c=[1 1 1 3 1 5 1 7 1 9 1 11 1 13 1 15 1 17 1 19 1; 2 1 2 1 1 4 1 1 6 1 1 8 1 1 10 1 1 12 1 1 14]; x=[tan(1);exp(1)]; y=contfrac(c); assert(max(abs(y-x))<1e-15)

[Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14]

5   Pass
%% c=(1:9)'*[1 2*ones(1,20)]; x=sqrt([2;5;10;17;26;37;50;65;82]); y=contfrac(c); assert(max(abs(y-x))<1e-15)

[Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14] [Warning: Matrix is singular to working precision.] [> In contfrac at 5 In verifyCode>evaluateCode at 227 In verifyCode at 40 In fevalJSON at 14]

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!