Newton method for nonlinear equations

21 Ansichten (letzte 30 Tage)
Ana Garvanlieva
Ana Garvanlieva am 13 Mär. 2015
Kommentiert: Torsten am 24 Mär. 2015
I have the following system of non-linear equations:
f(x)={(x(1)^5 + x(2)^3*x(3)^4 + 1)
(x(1)^2*x(2)*x(3))
(X(3)^4 - 1)}
Do you know, and can you help me with the code for the Newton method. As help I have instructions to note some difficulties with convergence and "As a remedy implement a damped Newton modification using the Armijo-Goldstein criterion."
  7 Kommentare
Torsten
Torsten am 17 Mär. 2015
I wonder why you don't use the Jacobian you calculated in an earlier thread:
n=20;
f=@(x)[x(1)^5+x(2)^3*x(3)^4+1 ; x(1)^2*x(2)*x(3) ; x(3)^4-1 ];
Df=@(x)[5*x(1)^4 3*x(2)^2 4*x(3)^3
2*x(1)*x(2)*x(3) x(1)^2*x(3) x(1)^2*x(2)
0 0 4*x(3)^3];
x = [.1;.1;.1]; % starting guess
for i = 1: n
Dx = -Df ( x )\ f( x ); % solve for increment
x = x + Dx; % add on to get new guess
f (x ); % see if f(x ) is really zero
end
Best wishes
Torsten.
Ana Garvanlieva
Ana Garvanlieva am 17 Mär. 2015
Thank you for replaying Torsten... So i did this: in Command window i wrote:
syms x1 x2 x3 J = jacobian([x1^5 + x2^3*x3^4 + 1; x1^2*x2*x3; x3^4-1],[x1;x2;x3]);
And i run the code from your post. It gives me:
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 6.940734e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 7.145906e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 7.359285e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 7.579619e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 7.806710e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 8.040648e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 8.281610e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 8.529801e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 8.785447e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 9.048804e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 9.320218e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 9.600300e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 9.890515e-020.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.019509e-019.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.052724e-019.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.092946e-019.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.154018e-019.
> In proba at 8
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.281592e-019.
> In proba at 8

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Torsten
Torsten am 17 Mär. 2015
You don't need to write the above lines in the command window - just execute the code above.
Can you output x and f(x) in the for-loop ? What values do you get ?
The x-values should either converge towards (-1,0,1) or towards (0,-1,1).
The f(x)-values should converge towards (0,0,0).
If this is not the case, use the hint to implement the damped Newton method.
In principle, this means that you replace the line
x = x + Dx; % add on to get new guess
by
x = x + lambda*Dx; % add on to get new guess
where 0 < lambda < 1 is calculated according to some rule.
Best wishes
Torsten.
  10 Kommentare
Torsten
Torsten am 24 Mär. 2015
No, it's not ok. As I said before, the values of x must tend towards (-1,0,1) or towards (0,-1,1).
The f(x)-values should converge towards (0,0,0).
Maybe this code works better:
n=20;
f=@(x)[x(1)^5+x(2)^3*x(3)^4+1 ; x(1)^2*x(2)*x(3) ; x(3)^4-1 ];
Df=@(x)[5*x(1)^4 3*x(2)^2 4*x(3)^3
2*x(1)*x(2)*x(3) x(1)^2*x(3) x(1)^2*x(2)
0 0 4*x(3)^3];
T=@(x)0.5*(f(x))'*f(x);
tau=0.5;
x = [-.01;-.01;-.01]; % starting guess
for i = 1: n
Dx = -Df (x)\f(x); % solve for increment
lambda=1.0;
while T(x+lambda*Dx)-T(x) > -0.5*lambda*T(x)
lambda=tau*lambda;
end
x=x+lambda*Dx;
f(x); % see if f(x) is really zero
fprintf('value of x: %d\n', x);
fprintf('value of function: %d\n', f(x));
end
Best wishes
Torsten.
Torsten
Torsten am 24 Mär. 2015
Jacobian is wrong ; use this version:
n=20;
f=@(x)[x(1)^5+x(2)^3*x(3)^4+1 ; x(1)^2*x(2)*x(3) ; x(3)^4-1 ];
Df=@(x)[5*x(1)^4 3*x(2)^2*x(3)^4 x(2)^3*4*x(3)^3
2*x(1)*x(2)*x(3) x(1)^2*x(3) x(1)^2*x(2)
0 0 4*x(3)^3];
T=@(x)0.5*(f(x))'*f(x);
tau=0.5;
x = [-.01;-.01;-.01]; % starting guess
for i = 1: n
Dx = -Df (x)\f(x); % solve for increment
lambda=1.0;
while T(x+lambda*Dx)-T(x) > -0.5*lambda*T(x)
lambda=tau*lambda;
end
x=x+lambda*Dx;
f(x); % see if f(x) is really zero
fprintf('value of x: %d\n', x);
fprintf('value of function: %d\n', f(x));
end
x should converge towards (-1,0,-1), f(x) should converge towards (0,0,0).
Best wishes
Torsten.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by