I need to evaluate the following series:
where u(n) is given by the recurrence relation:
The first and second terms are given as 0.5 and 0.6 respectively. The loop needs to end when un > 1e-8. The problem I have is that it seems that this series will never go below 0.5 so why even limit it to such a small number? Obviously the loop will just go on ad infinitum?
Anyway this is my code:
u(1) = 0.5;
u(2) = 0.6;
S = u;
n = 1;
while (abs(u(n)) >= 1e-8)
n = n + 1;
u(n+1) = u(n-1)^2 + u(n)^2;
S(n) = u(n) + S(n-1);
end
disp(S)
The first 6 cumulative terms I get with this code are 0.5; 1.1; 1.71; 2.4421; 3.35017; 4.71073 (in the array I defined as S), but then it rapidly moves up to infinity. I just want some confirmation on my code and whether I'm not misinterpreting something.

 채택된 답변

Torsten
Torsten 2016년 2월 16일
Your argument is correct.
Here is your modified code:
u(1) = 0.5;
u(2) = 0.6;
S(1) = u(1);
S(2) = u(1) + u(2);
n = 2;
while (abs(u(n)) >= 1e-8)
n = n + 1;
u(n) = u(n-2)^2 + u(n-1)^2;
S(n) = u(n) + S(n-1);
end
disp(S)
Best wishes
Torsten.

댓글 수: 1

Ah, thanks for the response and the feedback on the code. I was wondering if my sum array was logically defined.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2016년 2월 16일

댓글:

2016년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by