Matlab - fixed point iterations for general equation (nonlinear)
fixed point iterations:
find solution of X = F(X) as a limit of a sequence Xi+1 = F(Xi), i = 1, 2, ...
(X can be a nuber, a vector, a matrix ...)
fixed point iterations for real equation:
ex. 1: x = sin(x) + 1
graphical solution:
>> x=[-3:0.2:3]; >> plot(x, sin(x) + 1, x, x)numerical solution:
>> x = 6; % choose an initial value >> x = sin(x) + 1 % repeat, until x stays unchanged
ex. 2: x = 2 - cos(x/2)
>> x = 3; % choose an initial value >> x = 2 - cos(x/2) % repeat, until x stays unchanged
graphical solution:
>> x=[-3:0.2:3]; >> plot(x, 2 - cos(x/2), x, x)
ex. 3: x = 2 - 3*cos(x)
>> x = 3; % choose an initial value >> x = 2 - 3*cos(x) % does not converge
check graphically that the solution exists:
>> x=[-3:0.2:3]; >> plot(x, 2 - 3*cos(x), x, x)
fixed point iterations for vector equation: X = F(X), X = ( x1, x2 )T
ex. 4: F(X) = ( cos((x1-x2)/4), sin(x1+x2)/3 )T
>> X = [0 ; 0]; % choose an initial value >> X = [cos((X(1)-X(2))/4); sin(X(1)-X(2))/3 ] % repeat until convergence
ex. 5: F(X) = ( cos(4·(x1-x2)), 3·sin(x1+x2) )T
>> X = [0 ; 0]; % choose an initial value >> X = [cos(4*(X(1)-X(2))); 3*sin(X(1)-X(2)) ] % does not converge
ex. 6 - linear equation: F(X) = ( p·(a·x1+b·x2) + v1 , p·(c·x1 + d·x2) + v2)T
>> a=2; b=3; c=1; d=2; p = 0.1; v = [3 ; 6]; % choose the parameters >> X = [0 ; 0]; % choose an initial value >> % write the example in matrix form: >> A = [a b ;c d]; >> X = p*A*X + v % repeat; the convergence depends on value of p >> max(abs(eig(p*A))) % spectral radius of the matrix p*A