Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 222227

Submitted on 23 Mar 2013 by Jean-Marie SAINTHILLIER

Correct

33Size
Leading solution size is 21.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
c=ones(1,40);
x=(1+sqrt(5))/2;
y=contfrac(c);
assert(abs(y-x)<1e-15)

                    
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)

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

                    
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)

                    
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)