Behavior of a sequence
7 views (last 30 days)
Show older comments
How to find the behavior of the sequence {yn} as n → infinity while yn+1 =5/2 yn +yn-1 ,y0 =y1 =1 in MATLAB?
2 Comments
Answers (3)
Ameer Hamza
on 7 Oct 2020
Edited: Ameer Hamza
on 7 Oct 2020
As I answered in your other question here, following code is used to solve the equation
a = [1 -5/2 -1];
b = 0;
ic = [1 1];
n = 50; % 50 terms
y1 = [ic(1) filter(b, a, ones(1, n-1), ic)];
First, you can see from the equation that all the terms are increasing, so the step size is also increasing. So you can conclude that the limit value is infinity.
To see what happens when n approaches infinity using code, use a large value of 'n'. For example
n = 1000; % 1000 terms
y1 = [ic(1) filter(b, a, ones(1, n-1), ic)];
and check the last value of y1
>> y1(end)
ans =
Inf
It also shows that the limit is infinity.
2 Comments
Ameer Hamza
on 7 Oct 2020
For example, if you plot
plot(y1)
You can see that it is increasing rapidly. How else do you want to represent infinity?
Walter Roberson
on 7 Oct 2020
%function for fixed point iteration
yn=@(y1,y0) (5/2)*y1+y0;
%all initial guess
yy0=1; yy1=1;
y_val(1)=yy0; y_val(2)=yy1;
cnt=2; tt(1)=0;tt(2)=1;
%loop for all y
for i=1:10
cnt=cnt+1;
y_val(cnt)=yn(yy1,yy0);
yy0=yy1; yy1=y_val(cnt);
tt(cnt)=cnt-1;
end
%plotting the result
plot(tt,y_val)
xlabel('iterations')
ylabel('y_n')
title('y_n vs. iteration plot')
fprintf('The solution is diverging and tends to infinity at t tends to infinite.\n')
%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%
plot(tt(1:end-1), y_val(2:end)./y_val(1:end-1))
Notice how the ratio between adjacent terms quickly becomes nearly constant. That means that the sequence tends towards
Constant1 * Constant2^n
0 Comments
John D'Errico
on 7 Oct 2020
I won't do your homework for you. But I will offer some background to the solution.
yn+1 =5/2 yn +yn-1 ,y0 =y1 =1
This is known as a difference equation. The most common example you will see is the Fibonacci sequence. In that case, we have an integer sequence, generated by a difference equation, much like yours.
In fact, there are a lot of similarities between differential equations and these difference equations. Yours is specifically a LINEAR difference equation, so nothing really exotic or fancy.
One thing you should recognize, is that compared to the Fibonacci sequence, which does grow exponentially (see the Binet formula for elements of the Fibonacci sequence) your sequence should grow MORE rapidly. That is because the linear coefficients on the terms in your problem are larger than 1.
One interesting thing about a linear difference equation, is the solution can be quite similar to how you would solve a linear differetial equation. That is, you solve for the roots of the characteristic polynomial. Again, while I won't do your homework, I'll give you a bit of a hint. That is, how could we derive the Binet formula for the Fibonacci sequence?
The Fibonacci squence is defined by
y(n + 1) = y(n) + y(n-1)
y(0) = 0
y(1) = 1
This yields a characteristic polynomial of
lambda^2 - lambda - 1
We can solve for the roots of that polynomial as
syms lambda
lambda = solve(lambda^2 - lambda - 1)
So we have two roots. The formula for the series in general will be
Y(n) = a1*lambda1^n + a2*lambda2^n
syms a1 a2
syms y(n)
y(n) = a1*lambda(1)^n + a2*lambda(2)^n
yfib = solve(y(0) == 0,y(1) == 1,a1,a2)
yfib.a1
yfib.a2
We can then recreate the Binet formula for the Fibonacci series as simply
binet = subs(y,yfib)
You never know. You might even be able to solve your difference equation in a similar way.
1 Comment
John D'Errico
on 7 Oct 2020
Edited: John D'Errico
on 7 Oct 2020
Note: I'm sorry about the output looking strange here. That is the fault of Answers, not me. I looks fine when I edit the post, but then it got all bolloxed up after it was saved. Even if I go back and edit my post, all looks perfect. It is only after the post is saved that Answers has a problem. I've reported that fact to the person most likely to be responsible though.
The code I wrote is correct though. It should look perfectly correct when viewed as a LiveScript in MATLAB, for example.
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!