Multivariate Newton Method - Numerical Aproximation in Matlab

8 visualizaciones (últimos 30 días)
mathLAB
mathLAB el 8 de Sept. de 2016
Comentada: mathLAB el 18 de Mayo de 2020
I have to use Newton Method for a function goes R^5 to R^5 and gives an matrix's approximate eigenvalues and eigenvectors but whatever I did (even every step looks perfectly right) my answers are not even close to original eigenvalues and eigenvectors. (I checked it by using [m,n]=eig(B) code) Any help would be appreciated!
Matrix B and my initial guess is below;
%Using loop to create a matrix with two condition
for k=1:4
for l=1:4
if abs(k-l)==1
B(k,l)=-1/2;
else
B(k,l)=0;
end
end
end
B;
x=[-.5; -.5; -.5; -.5; -1]
My code is below:
%Definition of Matlab function
function [y]=new(n,x,B)
%Creating eigenvector as v=(v(1),v(2),v(3),v(4))
v=zeros(4,1);
v(1)=x(1);
v(2)=x(2);
v(3)=x(3);
v(4)=x(4);
%Defining function as desired to be
y=[B*v-x(5)*v;v'*v-1];
J=[B-x(5)*eye(4) -v; 2*v' 0];
%Using loop to end iteration as to error
for k=1:n
if max(abs(y))>1e-4
x=x-J\y
else
break
x
end
end
end

Respuesta aceptada

Michael Wang
Michael Wang el 13 de Sept. de 2016
Hi. I understand that you are trying to use the Newton Method to approximate eigenvalues and eigenvectors. I am assuming you are using the same method as it is described here. The goal for the Newton’s method is to approximate an eigenvalue and a corresponding eigenvector through updating the vector x, and vector v in your case, iteratively. In the code you provided, since the start of the for loop is defined after the calculation of vector v as well as the vector y and matrix J, these values will not be updated in each iteration. To fix this you should move the start of the for loop to the beginning of your function. Here is the modified code:
%Definition of Matlab function
function [y]=newZ(n,x,B)
%Using loop to end iteration as to error
for k=1:n % <-----------move your for loop to here
%Creating eigenvector as v=(v(1),v(2),v(3),v(4))
v=zeros(4,1);
v(1)=x(1);
v(2)=x(2);
v(3)=x(3);
v(4)=x(4);
%Defining function as desired to be
y=[B*v-x(5)*v;v'*v-1];
J=[B-x(5)*eye(4) -v; 2*v' 0];
if max(abs(y))>1e-4
x=x-J\y
else
break
x
end
end
end
Hope this helps!

Más respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by