KLineD
May 2nd, 2005, 11:12 PM
Hi everyone.
I've implemented a recursive function in Java for my Digital Control course.
The function to implement is the following:
output(n) = .5*input(n-1)+1.9*output(n-1)+.9*output(n-2)
input is another function that returns 0 when (n-1) < 0 or else returns 1.
I already implemented a recursive function that does this, but my teacher says it's not very efficient since if I have to get the value for n = 100 the program has to calculate every value up to 100.
My question is, can this be done in a non recursive way?? My teacher says that I have to take n (for example 100) and calculate the output for 99 and 98 and then sum everything and that's it, but I can't see how am I supposed to calculate for n=99 if I need to know the output for n=98 and 97... all the way down to 0 where I know what's the output.
Any help is very appreciated.
I've implemented a recursive function in Java for my Digital Control course.
The function to implement is the following:
output(n) = .5*input(n-1)+1.9*output(n-1)+.9*output(n-2)
input is another function that returns 0 when (n-1) < 0 or else returns 1.
I already implemented a recursive function that does this, but my teacher says it's not very efficient since if I have to get the value for n = 100 the program has to calculate every value up to 100.
My question is, can this be done in a non recursive way?? My teacher says that I have to take n (for example 100) and calculate the output for 99 and 98 and then sum everything and that's it, but I can't see how am I supposed to calculate for n=99 if I need to know the output for n=98 and 97... all the way down to 0 where I know what's the output.
Any help is very appreciated.