Cody

Solution 209868

Submitted on 27 Feb 2013 by James
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)
ans = 2 ans = 1.5000 ans = 1.6667 ans = 1.6000 ans = 1.6250 ans = 1.6154 ans = 1.6190 ans = 1.6176 ans = 1.6182 ans = 1.6180 ans = 1.6181 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180 ans = 1.6180
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)
ans = 1.0714 ans = 3.9333 ans = 1.2542 ans = 2.7973 ans = 1.3575 ans = 1.7367 ans = 1.5758 ans = 292.6346 ans = 1.0034 ans = 15.9966 ans = 7.0625 ans = 3.1416
3   Pass
%% c=[3 7 15 1]; x=355/113; y=contfrac(c); assert(abs(y-x)<1e-15)
ans = 16 ans = 7.0625 ans = 3.1416
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)
ans = 20.0000 1.0714 ans = 1.0500 1.9333 ans = 17.9524 12.5172 ans = 1.0557 1.0799 ans = 15.9472 1.9260 ans = 1.0627 10.5192 ans = 13.9410 1.0951 ans = 1.0717 1.9132 ans = 11.9331 8.5227 ans = 1.0838 1.1173 ans = 9.9227 1.8950 ans = 1.1008 6.5277 ans = 7.9084 1.1532 ans = 1.1264 1.8672 ans = 5.8877 4.5356 ans = 1.1698 1.2205 ans = 3.8548 1.8194 ans = 1.2594 2.5496 ans = 1.7940 1.3922 ans = 1.5574 2.7183
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)
ans = 2.5000 4.2500 6.1667 8.1250 10.1000 12.0833 14.0714 16.0625 18.0556 ans = 2.4000 4.2353 6.1622 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4167 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4138 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4143 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 2.4142 4.2361 6.1623 8.1231 10.0990 12.0828 14.0711 16.0623 18.0554 ans = 1.4142 2.2361 3.1623 4.1231 5.0990 6.0828 7.0711 8.0623 9.0554