필터 지우기
필터 지우기

Multivariate Newton Method - Numerical Aproximation in Matlab

조회 수: 4 (최근 30일)
mathLAB
mathLAB 2016년 9월 8일
댓글: mathLAB 2020년 5월 18일
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

채택된 답변

Michael Wang
Michael Wang 2016년 9월 13일
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!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by