- •Затверджено
- •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
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)
Example 2.3. Sensitivity of Newton's method to the choice of initial approximation.
1. Function in listing 2.5.
Listing 2.5. File f24.m
function y=f24(x)
y=(x-1.3)./((x-1.3).^2+1);
2. Derivative in listing 2.6.
Listing 2.6. File f241.m
function y=f241(x)
y=(1-(x-1.3).^2)./((x-1.3).^2+1).^2;
3. Script (listing 2.6) to run Newton method with different accuracy.
Listing 2.7. test.m
[root1, iter1] = newton('f24','f241', 1.87,1e-8);
% Check roots
y=f24(root1)
[root2, iter2] = newton('f24','f241', 1.88,1e-8);
y1=f24(root2)
% Compare the number of iterations
iter1
iter2
4. The results of the functions in the command window.
>> test1
y = 0
y1 =4.1016e-030
iter1 = 7
iter2 = 100
We see that the number of iterations in the first case is much smaller than in the second.
2.3.2 The method of simple iteration
To use this method, the original nonlinear equation f(x) = 0 can be written as
x = φ(x).
Let them know the root of the initial approximation x = x0. Substituting this value in the right side of the equation we obtain a new approximation:
x1 = φ(x0).
Repeat this procedure with x1 and obtain x2 = φ(x1). Repeating this procedure, we obtain a sequence
x0, x1, … , xn, … ,
called the iterative sequence.
Iterative sequence can be both convergent and divergent, as determined by the type of function f(x).
A sufficient condition for the convergence of the iterative process
Suppose that the equation x = φ(x) has a unique root on the interval [a, b] and the following conditions:
φ(x) is defined and differentiable on [a, b].
φ(x) € [a,b] for all x € [a, b].
There exists a real number q, that | φ'(x)|≤q<1 for all x € [a, b].
Then the iterative sequence xn = φ(x n-1) (n= 1, 2, …) converges for any initial approximation x0 € [a, b].
Example 2.4. Find the root of the equation
x4 - 11x3 + x2 +x +0.1 = 0
for k iteration using the method of simple iteration.
Let Iter.m file(function Iter) contains a simple iteration method and calculates the accuracy achieved by k iterations. Format function Iter:
[root,accuracy]=Iter(fun_fi,fun_derivative_fi,a,b,count_itarations)
Define function f(x)= x4 - 11x3 + x2 +x +0.1,
function fi(x)= -x4 + 11x3 - x2 -0.1,
and first derivative fi1(x)= -4x3 + 33x2 - 2x,
using the inline command:
>>f=inline(‘x.^4-11*x.^3+x.^2+x+0.1’);
>>fi=inline(‘-x.^4+11*x.^3-x.^2-0.1’);
>>fi1=inline(‘-4*x.^3+33*x.^2-2*x’);
To separate the roots graph of the function by executing the following sequence of operators:
>>x1=-1;
>>x2=1;
>>dx=10^-3;
>>x=x1:dx:x2;
>>plot(x,f(x)); grid on
Select interval localization – [-1,1] and calculate the value of the root of the equation on this interval and accuracy ε for k=6 iterations:
>>k=6;[root,eps]=Iter(fi,fi1,-1,1,k)
Individual tasks
Variants of the tasks are presented in the Appendix A column2(p.77).
Found a roots of the given equations if accuracy is less than = 10-4. Use:
a) Newton method;
b) Iterative method.
Locate one of the roots with several relative errors. Compare the amount of calculations using these methods for different errors.
Along with the "manual" solution provide solutions obtained by standard means of MatLab (functions fzero and root).
2.5 Control questions
Stages of the decision of the nonlinear equations.
Newton method. Illustrate on the graph. Merits and demerits of a method.
The method of simple itaration. Illustrate on the graph. Merits and demerits of a method.
Input and output arguments of the functions roots and fzero.
