Solving Recurrence Relations in Matlab: A Homework Challenge

In summary, the lecturer realized that the constraint: u(n) < 10^(-8) is an error and has stated that we can simply show that we managed to correctly code the recurrence relation, or solve it with the correct constraint.
  • #1
emergentecon
57
0

Homework Statement


Evaluate the following series ∑u(n) for n=1 → [itex]\infty[/itex] in which u(n) is not known explicitly but is given in terms of a recurrence relation.
You should stop the summation when u(n) < 10^(-8)
u(n+1) = (u(n-1))^2 + (u(n))2 with u(1) = 0.5, u(2) = 0.6

Note 1:The lecturer realized that the constraint: u(n) < 10^(-8) is an error and has stated that we can simply show that we managed to correctly code the recurrence relation, or solve it with the correct constraint.

Note 2: I am not looking for the answer, simply guidance on how to proceed / what I am doing wrong / not seeing?

Homework Equations


u(n+1) = (U(n-1))^2 + (u(n))2
u(1) = 0.5
u(2) = 0.6


The Attempt at a Solution


I have three attempts to this problem.

Attempt 1
I simply used excel to see how the values of u(n) evolved in order to verify any solution obtained in MATLAB . . . the values are:

0.61000000000000000
0.62210000000000000
0.75910841000000000
0.96325398813272800
1.50410382378633000
3.19018655838228000
12.43961859001160000

Attempt 2 - MATLAB
This implementation looks intuitively incorrect to me - plus the actual results to not correspond with what I attained in Excel.
clc; clear;
x1 = 0.5; x2 = 0.6; x3=0; counter=0;
while x1>10^-8;
counter=counter+1
x3 = x2 + x1;
x4 = x3 + x2;
x1 = x1^2;
x2 = x2^2;
x3
x4
end

Attempt 3 - MATLAB
This implementation looks more correct, but I get an error message? It is clearly missing the summation element, but am more concerned with getting the actual recurrence relation correct at this point.

clc; clear;
y(0) = 0.5; y(1) = 0.6; m = 0;
for m=1:10;
y(m+1)=(y(m))^2+(y(m-1))^2;
end

Error Mesage:
? Attempted to access (0); index must be a positive integer or logical.

Error in ==> New at 2
y(0) = 0.5; y(1) = 0.6; m = 0;
 
Physics news on Phys.org
  • #2
clc; clear;
y(1) = 0.5; y(2) = 0.6;
for m=2:11;
y(m+1)=(y(m))^2+(y(m-1))^2;
end
 
  • Like
Likes 1 person
  • #3
Thanks! But, hmmmm . . . why is that an issue?
Why could m not be -1?
Also the results seem to be different from what I get in excel - could this be a floating-point issue?

Excel:=
0.6100
0.6221
0.7591
0.9633

Matlab(your solution):=
0.6100
0.7321
0.9081
1.3606


EDIT:Ok my two solutions now agree - had mixed y(1) and y(2) values . . .

Thanks again!
 
Last edited:
  • #4
I get in Excel the same results.
 
  • Like
Likes 1 person
  • #5
Thanks!
 
  • #6
I am just playing around with the equation now . . . trying to implement a constraint for u(n) < 10^8 {not 10^-8 as originally stated}. Here I would use:

clc; clear;
y(1) = 0.5; y(2) = 0.6;
while y(m)<10^8;
y(m+1)=(y(m))^2+(y(m-1))^2;
end

I have also tried: while y<10^8

Both generate the error that m is an undefined function or variable?
Am curious as to how I might implement this?
I figure I just have a simple syntax issue?
 
  • #7
clc; clear;
y(1) = 0.5; y(2) = 0.6;
m=2;
while y(m)<10^8;
y(m+1)=(y(m))^2+(y(m-1))^2;
m=m+1;
end
 
  • Like
Likes 1 person
  • #8
Again, thanks, really!
Any chance you could explain why my original approach wouldn't work?
 
  • #9
You did not specified what m should be.
 
  • Like
Likes 1 person
  • #10
Aaaaaahhhhh, ok . . . yes yes I see. Having removed the 'for m=2:11' etc. etc. Yeah yeah.
Cool, thanks man!
 

1. What is a recurrence relation in Matlab?

A recurrence relation in Matlab is a mathematical equation that defines a sequence of values based on previous values in the sequence. It is a way to express a problem in a recursive manner, where a solution to a smaller instance of the same problem can be used to solve a larger instance.

2. How is a recurrence relation represented in Matlab?

A recurrence relation is typically represented in Matlab using a function or a loop. The function will take in the initial values and the parameters of the recurrence relation, and then use a loop to calculate the subsequent values based on the previous ones.

3. What are the benefits of using a recurrence relation in Matlab?

Using a recurrence relation in Matlab can help simplify complex problems and reduce the amount of code needed to solve them. It also allows for more efficient use of memory and computation time, as the values are calculated iteratively instead of storing them in memory.

4. Are there any limitations to using recurrence relations in Matlab?

One limitation of using recurrence relations in Matlab is that they can be computationally intensive for larger sequences or complex equations. Additionally, if the initial values are not specified or calculated correctly, the results may be inaccurate.

5. How do I know if a problem can be solved using a recurrence relation in Matlab?

A problem can be solved using a recurrence relation in Matlab if it can be broken down into smaller sub-problems that have the same structure and can be solved using the same equation. It is important to check if the initial values and parameters are well-defined and if the problem can be solved iteratively before using a recurrence relation.

Similar threads

Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
283
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Calculus and Beyond Homework Help
Replies
10
Views
989
  • Calculus and Beyond Homework Help
Replies
5
Views
1K
  • Calculus and Beyond Homework Help
Replies
6
Views
959
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Calculus and Beyond Homework Help
Replies
12
Views
1K
  • Calculus and Beyond Homework Help
Replies
9
Views
2K
  • Calculus and Beyond Homework Help
Replies
11
Views
1K
Back
Top