Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
MV_Eng_OTP(part1)_2013.doc
Скачиваний:
0
Добавлен:
01.04.2025
Размер:
1.3 Mб
Скачать

Inverse matrix:

where I is the identity matrix.

We can write

This is done in MATLAB using the matrix inverse function (inv): x=inv(A)*b.

>> i=inv(A)*V

i =

17.0588

9.0784

-5.7843

7.9804

14.8627

Kramer’s formula:

>> DetA=det(A)

DetA =

-51

>> A1=[V A(:,2:end)]

A1 =

41 0 0 3 0

0 1 0 -3 1

38 0 -4 0 1

0 -1 0 -1 0

0 1 -1 0 -1

>> DetA1=det(A1)

DetA1 =

-870

>> A2=[A(:,1) V A(:,3:end)]

A2 =

1 41 0 3 0

0 0 0 -3 1

0 38 -4 0 1

1 0 0 -1 0

0 0 -1 0 -1

>> DetA2=det(A2)

DetA2 = -463

>> A3=[A(:,[1 2]) V A(:,[4 5])]

A3 =

1 0 41 3 0

0 1 0 -3 1

0 0 38 0 1

1 -1 0 -1 0

0 1 0 0 -1

>> DetA3=det(A3)

DetA3 =

295

>> A4=[A(:,1:3) V A(:,5)]

A4 =

1 0 0 41 0

0 1 0 0 1

0 0 -4 38 1

1 -1 0 0 0

0 1 -1 0 -1

>> DetA4=det(A4)

DetA4 = -407

>> A5=[A(:,1:end-1) V]

A5 =

1 0 0 3 41

0 1 0 -3 0

0 0 -4 0 38

1 -1 0 -1 0

0 1 -1 0 0

>> DetA5=det(A5)

DetA5 =

-7586.3.2

>> I(1)=DetA1/DetA;

>> I(2)=DetA2/DetA;

>> I(3)=DetA3/DetA;

>> I(4)=DetA4/DetA;

>> I(5)=DetA5/DetA;

>> I'

ans =

17.0588

9.0784

-5.7843

7.9804

14.8627

3.3.2 Iterative methods

Jacobi method

Let suppose that all diagonal elements aii i=1,2,…n, are nonzero. In this case we can write the system (3.1) in form:

(3.5)

Let first approximation to solution(initial guess) of system is equal zero:

Let's substitute these values in system of the equations (3.5) and we shall receive the following approximation to the solution. In common case, if we have calculated (k-1)-approximation we receive next approximation by formulas:

(3.6)

Repeating iterations for k=1,2,… we receive the sequence of vectors ( ), k=1,2,…

Theorem. If such conditions for diagonal elements aii , i=1,2,…n, hold:

or

.

the repeated application of the method results in the appearance of the sequence tending to solution of system (3.1) as limit.

When the sequence converges, the difference between two next approximations to the decision tends to zero. Hence, we can believe, that have received the decision with the necessary accuracy, if distance between two approximations to the decision became less given accuracy .

Distance between two vectors can be measured by several various ways:

  1. Distance is on the average calculated under the formula

  1. Distance on the maximal value of coordinate of a vector is calculated under the formula:

Which of the formulas to use is decided depending on the requirements of practice.

Example. Solve system of linear equations using iterative method:

4x1 – x2 + x3 = 4

2x1 + 6x2 - x3 = 7

x1 +2x2 -3x3 = 0

First of all we shall check up, whether the conditions of convergence for a method of simple iterations are carried out. As 4>2, 6>3 and 33, the convergence condition are carried out and we can use this method.

L et's express unknowns x1, x2, x3 accordingly from first, second and third equations:

x1 = (4 + x2 - x3 )/4

x2 = (7 - 2 x1 + x3 )/6

x3 = (x1 + 2 x2 )/3

It is easy to see that system has such solution: x1 =1, x2 =1, x3 =1.

As a first approximation (as usually) let’s give Next approximation we will receive if substitute these values in system of the equations (3.7):

Next approximations are :

You see that unknowns tend to 1 – the solution of this system.

Listing of file jacobi.m. Solution of the linear system Ax = b, from the initial value of x = P0, and generating the sequence {Pk}, which converges to the solution. Effective conditions for the use of the method is that A - is strictly diagonally dominant matrix.

b is an n-by-1 known column vector; and x is an n-by-1 column vector of unknowns.

function [x,k]=jacobi(A,b,P,eps,maxiter)

%Input data:

% - A - non-singular matrix of size n * n,

% - b is an n-by-1 known column vector;

% - P is an n-by-1 column vector of initial guess,

% - eps - the variable that determines the accuracy

% of numerical solutions,

% - maxiter - maximum number of iterations.

%Output data:

% – x is an n-by-1 column vector of unknowns,

% - k number of iterations.

n=length(b);

for k=1:maxiter

for i=1:n

x(i)=(b(i)-A(i,[1:i-1,i+1:n])*P([1:i-1,i+1:n]))/A(i,i);

end

err=abs(norm(x’-P));

P=x’;

if err<eps

break;

end

end

x=x’;

Zadel’s method

This method differs from a method of simple iterations(Jacobi method) by that new calculated of approximation to the decision is immediately substituted in the equation for calculation of the following approximation. Thus, the calculations are made under the following formulas:

(3.9)

Example. Let’s find the solution of system from the previous example by Zadel’s method. As a first approximation (as usually) let’s give

By formulas (3.9) we receive:

From this example you can see that method of Zadel tends to the solution of system more quickly than method of simple iterations.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]