What is the Pell series?
Pell series starts with the first term as 0 and the second term as 1. The next term will be an addition to the second last term and two times to the last term. Now, if we compute the third term it will be the sum of the second last term (0), and twice of the last term (21) is 2 (0+2).
The fourth term will be the sum of the second last term (1) and twice of the last term (22) is 5 (1+4).
We can find more terms using the same method.
Relation of Pell series number: T(n) = T(n-2) + 2T(n-1)
T(1) = 0
T(2) = 1
T(3) = 0+2*1 = 0+2 = 2
T(4) = 1+2*2 = 1+4 = 5
T(5) = 2+2*5 = 2+10 = 12
.
.
.
T(n) = T(n-2) + 2*T(n-1)
import java.util.*;
class Pell
{
Scanner sc=new Scanner(System.in);
void main()
{
int i,n,a=0,b=1,next;
System.out.print("\nHow many Elements:");
n=sc.nextInt();
System.out.print("Series as follows "+a+" "+b);
for(i=0;i<n-2;i++)
{
next=a+2*b;
System.out.print(" "+next);
a=b;
b=next;
}
}
}
No comments:
Post a Comment