Substitution Iteration in Matlab
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Joseph Cheng
am 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.
Antworten (2)
Roger Stafford
am 13 Jul. 2014
Bearbeitet: Roger Stafford
am 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 Kommentare
Roger Stafford
am 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.
Joseph Cheng
am 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 Kommentare
Joseph Cheng
am 14 Jul. 2014
Bearbeitet: Joseph Cheng
am 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).
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!