help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

programming recursion


From: BVBA NuKey Music
Subject: programming recursion
Date: Wed, 29 Oct 2008 11:10:55 +0100

I'm trying to program the following in octave (preferably matlab-compatible) using recursion:
Q(n)=T(n)/N(n)
with T(1)=N(1)=1
and
T(n)=T(n-1) + 2*N(n)
N(n)=T(n)+N(n)

I made up the following but this is not accepted by octave, can someone help me solve this like it should?
best regards,
nukeymusic

function answer = Q( n )

if( n == 0 )
answer = 1;
return;
else
answer = T(n) / N(n);
endif

endfunction

function answer = T( n )

if( n == 1 )
answer = 1;
return;
else
answer = T(n-1) + 2*N(n);
endif

endfunction

function answer = N( n )

if( n == 1 )
answer = 1;
return;
else
answer = T(n)+N(n);
endif

endfunction


On 9/6/07, Hugo Coolens <

reply via email to

[Prev in Thread] Current Thread [Next in Thread]