Using for loops with a recurrence relation to find intervals where the plot acts differently.
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Roger Stafford
2014-9-17
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!