Using for loops with a recurrence relation to find intervals where the plot acts differently.

2 vues (au cours des 30 derniers jours)
Bo
Bo le 16 Sep 2014
Commenté : Bo le 17 Sep 2014
Hi, I am given a recurrence relation:
y_n+1 = y(n) + h(-y(n)^2 + 4.5(y(n)) - 3.5) y_1 = (2)
Using for loops I am to iterate through this equation and then find 2 threshold values where the plot of the function act differently.
My code looks something like:
function y = recurrence(n)
h = 0:0.01:5;
N = 50000;
for k=1:length(h)
y = zeros(1, N+1);
y(1) = 2;
for n = 1:N
y(n+1) = y(n)+h(k)*((-y(n))^2+(4.5*y(n))-3.5);
end
end
Since my h interval is from 0 to 5 I am to find 2 values where the plot acts differently
from 0<h<h1 y(n) should approach 3.5 from h1<h<h2 y(n) should oscillate from h2<h y(n) should approach infinity
h1 is supposed to be .8 and h2 is supposed to be 1.2.
I am just having issues with making my code work correctly so I can find h1 and h2, any tips would greatly be appreciated!!! I feel like I may need to use if statements in order to find h1 and h2 but I am not quite sure where to put them/ what to do with them. Also I am not sure how to use plot(y) to view what type of activity y(n) is doing according to a certain h value.
Thank you

Réponses (1)

Roger Stafford
Roger Stafford le 17 Sep 2014
You have an error in your recurrence formula, the line
y(n+1) = y(n)+h(k)*((-y(n))^2+(4.5*y(n))-3.5);
should be
y(n+1) = y(n)+h(k)*(-y(n)^2+(4.5*y(n))-3.5);
That should make a considerable difference in your results.
On a brief trial on my computer it would appear that .8 and 1.2 are indeed the critical values of h. With me when h > 1.2 it went to minus infinity. To catch the critical h values I would think all you need to collect are the last few, maybe just the last two, values of y for each value of h, in order to catch the point of change. 501*2 is not a lot to have to store. Then check each of these via appropriate code to see if convergence has occurred and if so what they have converged to.
  1 commentaire
Bo
Bo le 17 Sep 2014
How did you go about collecting the last few values of y and check to see if convergence has occurred? that is where I am confused. How do I find my critical h values (.8 and 1.2) and how can i see the behavior of convergence near these h values? I am not sure how to implement code to do this.
Thank you!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by