[go: up one dir, main page]

0% found this document useful (0 votes)
24 views10 pages

Engg1801 2005 Lect7 With Functions

This document outlines MATLAB Lecture 7, focusing on solving sets of nonlinear algebraic equations using multivariable Newton's method. It includes examples, MATLAB code for implementation, and advice on iterative methods. The lecture emphasizes the importance of initial estimates and the use of functions to simplify complex calculations.

Uploaded by

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

Engg1801 2005 Lect7 With Functions

This document outlines MATLAB Lecture 7, focusing on solving sets of nonlinear algebraic equations using multivariable Newton's method. It includes examples, MATLAB code for implementation, and advice on iterative methods. The lecture emphasizes the importance of initial estimates and the use of functions to simplify complex calculations.

Uploaded by

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

ENGG 1801

Engineering Computing

MATLAB Lecture 7: Tutorial Weeks 11-13

Solution of nonlinear algebraic equations (II)


Outline of lecture
 Solving sets of nonlinear equations
 Multivariable Newton’s method
 Example (2 equations in 2 unknowns)
 Solving example problem in Matlab
 Functions
 Conclusions
Sets of Nonlinear Equations
 Equation sets can be large
– 100’s (1000’s) of equations
– Initial solution estimate can be a challenge
 Fewer solution options
– Plotting and direct substitution are not options
 Most widely used approach ?
– Multivariable Newton’s method
Multivariable Newton’s Method
 Single variable algorithm Scalar equation
xi 1  xi   f ' ( xi )  f ( xi )
1

– Each iteration solves a linear approximation to function

 Multivariable algorithm Vector-matrix equation

xi 1  xi  J ( xi )  f ( xi )
1

– Each function approximated by a linear equation


– Each iteration solves a set of linear equations
Example (I)
 Solve the pair of equations:
2
Solution is:
f1 ( x1 , x2 )  x1  x 0
2
f ( x , x )  x  x 0
1 1 2 1 2
2 f1 ( x1 , x2 )  x1 x2  8 0

f 2 ( x1 , x2 )  x1 x2  8 0
x1 = 4 x2 = 2

 Elements of the Jacobian matrix


 f1 f1 
 x 1 x2
 2 x2 
 1 
 f 2  x f 2
 x1 
2
 x1 x2 
Example (II)
 Use as initial estimate for solution (3, 3)
 Next estimate obtained from:
Functions evaluated
New point = (3.5714, 2.0952) at old point

1
 x1   3    1  6   6 
        
 x2   3   3 3  1 

Old point = (3, 3) Jacobian evaluated


at old point
Solution in Matlab
counter = 1;
error = 10;
xold = [3;3];
while error > 1e-3 & counter < 10
fold(1) = xold(1) - xold(2)^2; fold(2) = xold(1)*xold(2) - 8;
J(1,1) = 1; J(1,2) = -2*xold(2); J(2,1) = xold(2); J(2,2) = xold(1);
xnew = xold - inv(J)*fold'
error = max(abs(xnew(1)-xold(1)),abs(xnew(2)-xold(2)));
counter = counter + 1;
xold = xnew;
end
Advice on Iterative Methods

 Follow one cycle through code by hand


 Initially use modest convergence criterion
 Put in a ‘counter’ ( to prevent infinite loop )
 Check final solution
– Be prepared for multiple solutions
 Initial guess has a big impact:
– On the final solution obtained
– On the time taken to converge to solution
Functions
 Breaking up complex calculations into simpler
blocks.
 Main program
One to one correspondence
between inputs, outputs in
– a = 2; b = 3;
calling statement and in
– [answer, diff] = my_function(a,b)
function
 Separate file, my_function.m; outputs calculated
inside function using input arguments (in1 & in2)
– function [answ, differ] = my_function(in1,in2)
– answ = in1 + in2;
– differ = in1 – in2;
Conclusions
 Solution of nonlinear equation sets ?
– Very common problem in engineering
 Built-in
Matlab functions ( e.g. fsolve from
MATLAB’s Optimization Toolbox)
– User supplied Jacobian speeds convergence
– If unavailable → Matlab gets by finite differencing
– User has to supply initial estimate of solution
 Make your own functions to split up a big problem
into simpler pieces.

You might also like