Substitution Iteration in Matlab

12 views (last 30 days)
zhe yi soo
zhe yi soo on 11 Jul 2014
Commented: Roger Stafford on 15 Jul 2014
Hi, I am facing some problem in iterating my equations. Basically, here how it should work.
x(i) = x(i+1) + x(i+2)
starting from i =6
x(6) = x(5) +x(4), while x(5)= x(4)+ x(3)...etc
I would like to use loop to do this automatically as x(6) and x(-6) is known and I need to find x(0). But I have no idea how to do it. Can anyone help me in this?
  3 Comments
zhe yi soo
zhe yi soo on 11 Jul 2014
Thank you for the comment. I forgot about that. There is one more known value which is x(-6). So basically, what I am trying to do is to keep substituting the first equation until I get only one unknown. And by keep doing this, I will need to determine x(0) by the end.
Joseph Cheng
Joseph Cheng on 11 Jul 2014
Okay, so if i can dumb it down a bit. "we" have the first and last values in an array. the middle portions fit the x(i)=x(i-1)+x(i-2) format. I think this is doable.

Sign in to comment.

Answers (2)

Roger Stafford
Roger Stafford on 13 Jul 2014
Edited: Roger Stafford on 13 Jul 2014
Here is an alternative method of solving your problem. For the fibonacci iteration, x(i) = x(i-1) + x(i-2), we can solve the quadratic equation
t^2 = t + 1
to get t = (1+sqrt(5))/2 or t = (1-sqrt(5))/2, and we can conclude that x must satisfy
x(n) = A*((1+sqrt(5))/2)^n + B*((1-sqrt(5))/2)^n
for some constant values A and B. This must hold for n = 6 and n = -6 which gives two equations and the two unknowns A and B.
A*((1+sqrt(5))/2)^6 + B*((1-sqrt(5))/2)^6 = x(6)
A*((1+sqrt(5))/2)^(-6) + B*((1-sqrt(5))/2)^(-6) = x(-6)
Their solution using matlab's backslash operator is
AB = [((1+sqrt(5))/2)^6 ,((1-sqrt(5))/2)^6 ;...
((1+sqrt(5))/2)^(-6),((1-sqrt(5))/2)^(-6)] \ [x(6):x(-6)];
A = AB(1); B = AB(2);
Then
x(0) = A+B;
(Note: You can't actually have a matlab vector x indexed with 0 or -6, so you must name x(6), x)-6), and x(0) in the above in other ways, such as x6, xm6, and x0.)
  4 Comments
zhe yi soo
zhe yi soo on 14 Jul 2014
Hi, I am sorry that I simplified all the equations by ignoring the coefficients as there are constant coefficient for all variables of the four equations. Hence, A(i) is not equal to B(i). But basically it is right that all the equations are in that form where x1,x2,x3,x4,x5,x6,x7,and x8 are all known constansts.
A(i)= x1*B(i) + x2*B(i-1)
B(i)= x3*A(i) + x4*A(i-2)
A(i)= x5*B(i-1) + x6*A(i-2)
B(i)= x7*B(i-1) + x8*A(i-2)
Thanks
Roger Stafford
Roger Stafford on 15 Jul 2014
@Zhe Yi Soo. I have considered your modified set of iterative equations and have tentatively concluded that in order to have a non-zero solution for the A and B sequences it is necessary in general that the constants x1, x2, x3, ..., x8 satisfy two particular equalities. That is to say, the eight constants have only six degrees of freedom in their choice.
The analysis to establish this is sufficiently complicated that I am reluctant to burden this thread with a lengthy explanation of the reasoning behind this claim, so I pose this question. Given that there is such a restriction on the eight coefficients, is this something you still want to follow up on? If so, I would suggest you open up a new "Answers" thread and pose this modified question concerning the eight-parameter four-equation iterative relationship.

Sign in to comment.


Joseph Cheng
Joseph Cheng on 11 Jul 2014
Well there are a few ways to do it. if you lay out the equations substitutions you can get it such that xn = B*x2+A*x1; so if i say the first few array values are [a b c d e f g h ...] then
c = b+a;
d = c+b = 2b+a
e = d+c = 3b+2a
f = e+d = 5b+3a
g = f+e = 8b+5a
and so on..
so if we keep is simple and do x1 =50 and x6 = 400 then based on this 400 = 5*x2+3*50 gives x2=50 and then you can find any of the other middle values.
if you want to brute force it then
x1 = 1;
xn = 4050;
iter = 35;
possiblex2 =[];
xdiff = [];
for x2 = x1:round(xn/2)
xtemp = x2;
xm2 = x1;
x = [x1 x2];
for it = 3:iter
xtemp = xtemp + xm2;
xm2 = xtemp-xm2;
x = [x xtemp];
end
if xtemp == xn
possiblex2 = [possiblex2 x2];
disp(['possible x2 =' num2str(x2)]);
disp([x]);
else
xdiff = [xdiff xtemp-xn];
end
end
  7 Comments
Joseph Cheng
Joseph Cheng on 14 Jul 2014
Edited: Joseph Cheng on 14 Jul 2014
Are you sure about that last line of B(i)=B(i-1)+A(i-2)? then that would mean that A(i)=B(i)?
also based on equations 1 and 2 then A(i-2) = -B(i-1).
zhe yi soo
zhe yi soo on 14 Jul 2014
Hi, I am sorry that I simplified all the equations by ignoring the coefficients as there are constant coefficient for all variables of the four equations. Hence, A(i) is not equal to B(i). But basically it is right that all the equations are in that form where x1,x2,x3,x4,x5,x6,x7,and x8 are all known constansts.
A(i)= x1*B(i) + x2*B(i-1)
B(i)= x3*A(i) + x4*A(i-2)
A(i)= x5*B(i-1) + x6*A(i-2)
B(i)= x7*B(i-1) + x8*A(i-2)
Thanks

Sign in to comment.

Categories

Find more on Mathematics 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!