- •Затверджено
- •Contents Contents
- •The purpose and the contents of laboratory works
- •Laboratory work №1 Solution of Nonlinear Equations by the Bisection method and Chord method
- •1.1 Purpose of the work
- •1.2 Tasks for laboratory work
- •1.3 The basic theoretical knowledge
- •1.3.1 Bisection method
- •Figure 1.1 – Bisection method
- •Chord method
- •Figure 1.4 – Chord method
- •1.3.3 Matlab function fzero and roots
- •1.4 Individual tasks
- •1.5 Control questions
- •Laboratory work №2 Solution of Nonlinear Equations by the newton method and simple iteratIvE method
- •Figure 2.1 – Newton method
- •Figire 2.2 - Dependence of the number of iterations on the accuracy of methods for the bisection (upper line) and the Newton method (bottom line)
- •2.3.2 The method of simple iteration
- •A sufficient condition for the convergence of the iterative process
- •Individual tasks
- •Laboratory work №3 Solution system of Linear Algebraic Equations
- •3.3.1 Direct methods
- •Inverse matrix:
- •3.3.2 Iterative methods
- •Condition number of a
- •3.4 Individual tasks
- •3.5 Control questions
- •Laboratory work №4
- •Visualization of 3d data in matlab
- •Plot3(X, y, z, 'style')
- •4.3.2 Instructions: meshgrid, plot3, meshc, surfc
- •4.3.3 Instructions: sphere, plot3, mesh
- •4.3.4 The simple animation in 3d
- •1. Working with a sphere
- •4.3.5 Summary of 3d Graphics
- •Individual tasks
- •Laboratory work №5 Solving systems of nonlinear equations
- •5.1 Purpose of the work
- •5.2 Tasks for laboratory work
- •5.3 The basic theoretical knowledge
- •5.3.1 Newton method to solve systems of non-linear equations
- •5.3.2 Matlab function for Newton method for a system of nonlinear equations
- •5.3.3 The matlab routine function fsolve
- •Input Arguments
- •Individual tasks
- •5.5 Control questions
- •List of the literature
- •Appendix a.
- •Individual tasks to Lab number 1, 2
- •Appendex b. The task for self-examination to Lab number 1, 2
Chord method
The geometric meaning Chord method is to replace the chord of the curve y=f(x). Another approach is the intersection of the chord with the abscissa.
Figure 1.4 – Chord method
If [a,b] – a segment containing the root, the equation of the chord
For the point of intersection of the chord with the abscissa we have
,
taken for the next approximation to the root. Then choose one of the intervals , at the end of which the function has the values of different signs, ets…
Please note that all received one end of the intervals will be the same, namely the one on which sign function and the sign of the second derivative of the same. This end is called fixed, while the opposite end of the segment is taken as an initial approximation to the root. Let c - one of the ends of the segment, for which the condition , and - the initial value (the opposite end of the segment), then perform the iteration formula:
, k=0,1,2,…
1.3.3 Matlab function fzero and roots
Function fzero - find zero of a function of one variable.
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
[x,fval] = fzero(...)
[x,fval,exitflag] = fzero(...)
[x,fval,exitflag,output] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. fun is a function handle for either an M-file function or an inline function.The value x returned by fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search terminates when the search interval is expanded until an Inf, NaN, or complex value is found.
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1)) differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an interval guarantees fzero will return a value near a point where fun changes sign.
x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure options. You can define these parameters using the optimset function. fzero uses these options structure fields:
Display |
Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final' displays just the final output; 'notify' (default) displays output only if the function does not converge. |
FunValCheck |
Check whether objective function values are valid. 'on' displays a warning when the objective function returns a value that is complex or NaN. 'off' (the default) displays no warning. |
OutputFcn |
Specify a user-defined function that the optimization function calls at each iteration. |
TolX |
Termination tolerance on x |
[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition of fzero:
1 - Function converged to a solution x.
-1 - Algorithm was terminated by the output function.
-3 - NaN or Inf function value was encountered during search for an interval containing a sign change.
-4 - Complex function value was encountered during search for an interval containing a sign change.
-5 - fzero might have converged to a singular point.
[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the optimization:
output.algorithm Algorithm used
output.funcCount Number of function evaluations
output.intervaliterations Number of iterations taken to find an interval
output.iterations Number of zero-finding iterations
output.message Exit message
Using fzero for a function defined by inline command
The following command solves the equation
y = f(x) = x^3-5*x^2-x+2
starting from an initial guess of x = 4.
>>f=inline(‘x.^3-5*x.^2-x+2’);
>> fzero(f,4)
MATLAB returns the answer:
ans =
5.1190
Changing the initial guess to x = 2
>> fzero(f,2)
gives
ans =
0.5684
You can restrict the search to an interval by replacing the initial guess with an interval x€[3 6]:
z = fzero(f; [3 6])
Using fzero for a function defined in script file ‘fun’
Now, try solving the function defined in the script file fun.m.
>> x=fzero('fun', 4)
x =
5.1190
fzero uses a bisection approach to locating roots. Can you forsee any limitations to this? Try repeating the above with different initial conditions - how many roots can you locate?
MATLAB function roots
If the nonlinear algebraic system is a polynomial equation, we could use the MATLAB routine roots to find the zeros of the polynomial. Consider the same function f(x) = x3 - 5x2 -x +2 that we discussed earlier.
The user must create a vector of the coefficients of the polynomial, in descending order, p = [1 -5 -1 2]:
Then the user can type the following command roots(p) and MATLAB returns the roots.
EDU>> roots(p)
ans =
5.1190
-0.6874
0.5684
Confirm that x = 0.5684 is a root by typing f(0.5864).
EDU>> f(.5684)
ans =
-1.5495e-004