Iteration error iter=0
Show older comments
Hello,
I am trying to solve a 2nd order difference equation with given bounds. Specifically:
I need to solve for a sequence of
( for t = 1,2,...,50) such that:
$X_{t+2} = f( X_{t+1}, X_t) $, the exact function is inside the below loop.
Here is my code to solve this system, using shooting method. And it is very strange that I got a sequence of X are all equal for 0 for all t. And more strange, the number of iterations executed (which is denoted iter in the loop are 0).
I have been checking for hours, but could not find the mistake. If any one see what is wrong with my code, plz kindly let me know.
Thanks so much,
T = 5;
X = zeros(T+1,1)
X(1) = 10;
iter=0
while (abs(X(T+1)) > TOL);
X(2) = (LEFT + RIGHT)/2;
for i = 1:T-1;
X(i+2,1) = A * (1 + ALPHA * BETA)* (X(i+1,1))^ALPHA + (1-DELTA) * (1 + BETA) * X(i+1,1)...
- BETA * (A * (X(i,1))^ALPHA + (1 - DELTA) * X(i,1)) * (A * ALPHA * X(i+1,1)^(ALPHA - 1) + (1 - DELTA));
end;
if X(T+1,1)< 0
LEFT = X(2,1);
elseif X(T+1,1) > 0
RIGHT = X(2,1);
else break;
end;
iter=iter+1
end;
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!