0% found this document useful (0 votes)
5 views

CHE210 Tutorial4 2024

Uploaded by

Ufuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

CHE210 Tutorial4 2024

Uploaded by

Ufuk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CHE 210

Numerical Methods in
Engineering
Tutorial – 4
Newton’s Method
Ø We obtain Newton's iterative method before:

Ø However, it can only be used to solve nonlinear equations involving only a single variable.

Ø In order to use it to solve a set of nonlinear algebraic equations involving multiple variables We
know from Linear Algebra that we can take systems of equations and express those systems in the
form of matrices and vectors.
Ø We can express the nonlinear system as a matrix with a corresponding vector. Thus, the following
equation is derived:
The Jacobian Matrix
• In the vector calculation, the Jacobi matrix is the matrix containing all first-order
partial derivatives of a vector-valued function.

• A system of nonlinear equations has the form;

• Equations matrix;

• Define the matrix J(x) by .The matrix J is the derivative of the F matrix according
to its variables.
Multivariable Non-linear Equations
Problem: Find x such that F x = 0
*
( )
*

F ( x) = F ( x* ) + J ( x* )( x - x* ) Taylor Series
é ¶F1 ( x) ¶F1 ( x) ù
ê ¶x  ú
¶ x
ê 1 N
ú
J ( x) = ê    ú Jacobian Matrix
ê ¶FN ( x)  ¶FN ( x) ú
ê ¶x1 ¶x N ú
ë û
Þ x k +1 = x k - J ( x k ) -1 F ( x k ) Iteration function
Multivariable Non-linear Equations
Computational Aspects
Iteration : x k +1 = x k - J ( x k ) -1 F ( x k )
k -1
Do not compute J ( x ) (it is not sparse).
k +1
Instead solve : k
J ( x )( x - x ) = -F (x )
k k

Each iteration requires:


1.Evaluation of F(xk)
2.Computation of J(xk)
3.Solution of a linear system of algebraic equations whose coefficient
matrix is J(xk) and whose RHS is -F(xk)
Multivariable Non-linear Equations
Algorithm
𝑥 ! = Initial Guess, 𝑘 = 0
Repeat {
( ) ( )
Compute F x k , J F x k

Solve 𝐽" (𝑥 # )(𝑥 #$% − 𝑥 # )=-F (𝑥 # ) for 𝑥 #$%


𝑘 =𝑘+1

} Until 𝑥 #$% − 𝑥 # ) , 𝑓(𝑥 #$% ) small enough


Example 1 % Functions
f = @(x,y) x^2 + y^2 -3; % the equation is x^2 + y^2 -3
g = @(x,y) x*y - 1; % the equation x*y - 1
F = @(x,y)[f(x,y); g(x,y)];
% Jacobian function
% J = [df/dx, df/dy;
% dg/dx, dg/dy];
J = @(x,y) [2*x 2*y; y x];

% Initial guess for x and y


xy = [0.5; 1.5];

% Tolerance
tol = 10^-6;

err = 1;
while err>tol
xy_new = xy - J(xy(1),xy(2))\F(xy(1),xy(2));
err = abs(xy_new-xy);
xy = xy_new;
end
disp([xy,err])
% Functions

Example 1 f = @(x,y) x^2 + y^2 -3; % the equation is x^2 + y^2 -3


g = @(x,y) x*y - 1; % the equation x*y - 1
% Functions F = @(x,y)[f(x,y); g(x,y)];
f = @(x,y) x^2 + y^2 -3; % the equation is x^2 + y^2 -3 % Jacobian function
g = @(x,y) x*y - 1; % the equation x*y - 1 % J = [df/dx, df/dy;
F = @(x,y)[f(x,y); g(x,y)]; % dg/dx, dg/dy];
% Jacobian function J = @(x,y) [2*x 2*y; y x];
% J = [df/dx, df/dy;
% dg/dx, dg/dy]; % Initial guess for x and y
J = @(x,y) [2*x 2*y; y x]; xy = [0.5; 1.5];

% Tolerance
% Initial guess for x and y
tol = 10^-6;
xy = [0.5; 1.5];

% Tolerance iter= 100;


tol = 10^-6; for i=1:iter
xy_new = xy - J(xy(1),xy(2))\F(xy(1),xy(2));
err = 1; err = abs(xy_new-xy);
while err>tol if err<= tol
xy_new = xy - J(xy(1),xy(2))\F(xy(1),xy(2)); break
err = abs(xy_new-xy); end
xy = xy_new; xy = xy_new;
end end
disp([xy,err]) disp([xy,err])
Example 2 % Functions
f1 = @(x1,x2,x3) x3^3 + x1*x2 + 14*x2;
f2 = @(x1,x2,x3) x2*x3 + x1*x2 - 4*x2 + 4*x1;
f3 = @(x1,x2,x3) x2^2 - x3^2;
F = @(x1,x2,x3)[f1(x1,x2,x3); f2(x1,x2,x3);f3(x1,x2,x3)];
% Jacobian function
% J = [df1/dx1, df1/dx2 df1/dx3;
% df2/dx1, df2/dx2 df2/dx3;
% df3/dx1, df3/dx2 df3/dx3];
J = @(x1,x2,x3) [x2 14+x1 3*x3^2; x2+4 x3+x1-4 x2; 0 2*x2 -2*x3];
𝐽(𝑥! , 𝑥" , 𝑥# )= % Initial guess for x1,x2,x3
x = [10; 10; -10];

% Tolerance
tol = 1e-6;
err = 1;
while err>tol
x_new = x - J(x(1),x(2),x(3))\F(x(1),x(2),x(3));
err = abs(x_new - x);
x = x_new;
end
disp([x,err,F(x(1),x(2),x(3))])
Example 3
ØSolve the following nonlinear system

• Initial vector

• Define F(x) and J(x)

Solve 𝐽" (𝑥 # )(𝑥 #$% − 𝑥 # )=-F (𝑥 # ) for 𝑥 #$%


Example 3 % Functions
f1 = @(x1,x2,x3) 3*x1 -cos(x2*x3)-0.5;
f2 = @(x1,x2,x3) x1^2-81*(x2+0.1)^2+sin(x3)+1.06;
f3 = @(x1,x2,x3) exp(-x1*x2)+20*x3+(10*pi-3)/3;
F = @(x1,x2,x3)[f1(x1,x2,x3); f2(x1,x2,x3);f3(x1,x2,x3)];
% Jacobian function
% J = [df1/dx1, df1/dx2 df1/dx3;
% df2/dx1, df2/dx2 df2/dx3;
% df3/dx1, df3/dx2 df3/dx3];
J = @(x1,x2,x3) [3 x3*sin(x2*x3) x2*sin(x2*x3);
2*x1 -162*(x2+0.1) cos(x3); -x2*exp(-x1*x2) -x1*exp(-x1*x2) 20];

% Initial guess for x1,x2,x3


x = [0.1; 0.1; -0.1];

% Tolerance
tol = 10^-6;

err = 1;
while err>tol
x_new = x - J(x(1),x(2),x(3))\F(x(1),x(2),x(3));
err = abs(x_new-x);
x = x_new;
end
disp([x,err,F(x(1),x(2),x(3))])

You might also like