the loop is not converging it is giving me an infinite value(it is increasing)

clear variables
close all
clc
A = [1 1 2; 1 2 4; 1 2 5];
x = [1; 2; 3];
Error = 0.00001;
Diff= 1;
while Diff>Error
x1=A*x;
Diff=norm(x1-x);
x=x1;
end

1 Kommentar

still not working still not working the answer is infinity for x and NAN for Diff

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Torsten
Torsten am 20 Mai 2023
Verschoben: Matt J am 20 Mai 2023
Why do you think your fixed-point iteration should converge ?
If the absolute values of the eigenvalues of A were all < 1, it would work. But it is not the case:
A = [1 1 2; 1 2 4; 1 2 5];
eig(A)
ans = 3×1
7.1842 0.5728 0.2430

5 Kommentare

i did not understand you
what i am trying to do is tomultiply a matrix by a vector to get a new vector then use the new vector by multiplying it with the same matrix untill the vector stop changing (converges)
Torsten
Torsten am 20 Mai 2023
Verschoben: Matt J am 20 Mai 2023
Try A = 5. Take a vector x = 1. Then x1 = 5*1 = 5, x2 = 5*5 = 25,... No convergence.
Try A = 0.5. Take a vector x = 1. Then x1 = 0.5*1 = 0.5, x2 = 0.5*0.5=0.25,... Convergence.
What's the difference ? abs(A) < 1 ...
how can i make it work?
Torsten
Torsten am 20 Mai 2023
Verschoben: Matt J am 20 Mai 2023
What do you mean by "make it work" ? It works as you have programmed it and gives you the correct result for the matrix A and the initial vector x: Divergence.
i found the answer, i need to normalize the new vector before using it again. thank you

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 20 Mai 2023

Verschoben:

am 20 Mai 2023

Community Treasure Hunt

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

Start Hunting!

Translated by