not a bad idea but...
try this:
function ans = contfrac(c)
%%
c(:,1);
if size(c,2)>1
ans + 1./contfrac(c(:,2:end));
end
Test | Status | Code Input and Output |
---|---|---|
1 | Fail |
%%
c=ones(1,40);
x=(1+sqrt(5))/2;
y=contfrac(c);
assert(abs(y-x)<1e-15)
Error: Index exceeds matrix dimensions.
|
2 | Fail |
%%
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)
Error: Index exceeds matrix dimensions.
|
3 | Fail |
%%
c=[3 7 15 1];
x=355/113;
y=contfrac(c);
assert(abs(y-x)<1e-15)
Error: Index exceeds matrix dimensions.
|
4 | Fail |
%%
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)
Error: Attempted to access c(1); index out of bounds because numel(c)=0.
|
5 | Fail |
%%
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)
Error: Attempted to access c(1); index out of bounds because numel(c)=0.
|
13798 Solvers
177 Solvers
187 Solvers
68 Solvers
Solving Quadratic Equations (Version 1)
361 Solvers