- •Затверджено
- •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
Laboratory work №3 Solution system of Linear Algebraic Equations
3.1 Purpose of the work
This laboratory work helps students a)study of direct and iterativ methods for solving system of linear algebraic equations; b) the use of MATLAB for solving system of linear algebraic equations.
3.2 Tasks for laboratory work
To study the direct and iterative methods(Jacobi and Zejdel) for solving nonlinear equations.
Make a programs-functions to find the roots of the Jacobi and Zejdel methods.
To carry out the individual task.
Save results of the work (the programs,listing of calculation) at your personal files.
Draw up report.
3.3 The basic theoretical knowledge
A set of linear algebraic equations looks like this:
(3.1)
Here the n unknown xj , j=1, 2, … , n are related by m equations. The coefficients aij with i= 1, 2, … , m and j = 1, 2, … , n are known numbers, as are the right-hand side quantities bi , i =1, 2, …, m.
The set of numbers is called the solution of system (3.1) if their substitution x1 , x2 , …, xn in the equation terns the equations into identities.
3.3.1 Direct methods
Requirements for a Solution
If an exact solution to Ax = b exists, b must lie in the column space of A. If it does, then the system is said to be consistent(совместная). If the system is consistent, an exact solution exists.
Matlab’s function rank(A) gives the number of linearly independent columns in A.
If given the n-by-n matrix A and the n-by-1 vector, b
• the solution to Ax = b exists and is unique for any b if and only if rank(A) = n.
• rank(A) = n automatically guarantees that the system is consistent.
Cramer’s formulas
If D = det A 0, the system of linear equations (3.1) only has one solution and that it can be found by Cramer’s formulas. But, the calculation of these formulas requires the very large number of operations, therefore Cramer’s formulas is used only for systems with n not higher 3:
, i = 1, 2, … , n.
The method of inverse matrix
The system of equations (6.1) can be written in matrix-vector form:
Ax = b (3.2)
Here x = ( x1 , x2 , …, xn ) is a vector whose coordinates x1 , x2 , …, xn are the sought-for unknowns, b = ( b1 , b2 , …, bn ) is a vector whose coordinates are free terms of system (6.1) and A is the matrix of coefficients of the system. The left-hand side of (3.2) is the result of multiplying matrix A by column vector x (that is, by a one column matrix); hence (3.2) equates the vectors Ax and b and is equivalent to the system of n equalities between the coordinates of the vectors. Thus, we arrive the following problem: given a matrix A and a column vector b, find a column vector x such that Ax = b.
The inverse of a square matrix A is a matrix A-1 such that A-1 A = E, where E is unit matrix.
Theorem. Given that det A 0, the solution to a system of equations Ax = b is unique and has the form
x = A-1 b (3.3)
where A-1 is the inverse of the matrix A.
Note that inverse matrices are especially suitable when we have to solve several systems of equations with the same left-hand sides but different columns of free terms. Indeed, the main difficulty in solving a system of linear equations using an inverse matrix is to compute the inverse matrix itself.
The method of Gauss
In general terms, this method consists in successive elimination of the unknowns from the equations of system (3.1). The matrix (3.4) will be called the augmented matrix of system (3.1); the augmented matrix differs from the matrix of system by the additional (last) column, which is formed from the free terms of the system.
(3.4)
Gaussian elimination involves the transformation of successive matrices using the elementary transformations of a matrix ( according the rules for transforming matrices) to yield a matrix of the form:
From last equation we find xn =dn /cnn , …, x1 = d1 –c12 x2 - … -c1n xn.
Solving systems of equations with MATLAB
Example 3.1. Electric circuit. . .
Apply Kirchhoff's voltage law for each loop and charge conservation at the nodes:
In matrix-vector form:
Solve a system of linear equations,
Ax = b
Here A is a known n-by-n, nonsingular matrix, (its determinant is not equal to zero); b is an n-by-1 known column vector; and x is an n-by-1 column vector of unknowns.
Let R1=1, R2=1, R3=4, R4=3, R5=1, E1=41, E2=38.
Using the capabilities of MatLab for solving systems of linear algebraic equations by direct methods (Gauss, Inverse Matrix, Cramer's rule) to find the currents i1, i2, i3, i4, i5.
Gaussian elimination:
The matrix A is square (m = n) and nonsingular (det(A) <> 0):
This numerical technique is similar to the way you are used to when solving systems, i.e., elimination and substitution. In MATLAB this is done with the left division operator (\): x = A\b
>> A=[1 0 0 3 0
0 1 0 -3 1
0 0 -4 0 1
1 -1 0 -1 0
0 1 -1 0 -1]
>> V=[41;0;38;0;0]
>> i=A\V
i =
17.0588
9.0784
-5.7843
7.9804
14.8627