Sie sind auf Seite 1von 42

Introduction to Matrix

• Consider a system of n linear algebraic equations in n unknowns

a11x1 + a12x2 + ... + a1nxn = b1

a21x1 + a22x2 + ... + a2nxn = b2

... ... ... ...

an1x1 + an2x2 + ... + annxn = bn

• where aij, i = 1, 2, ..., n, j = 1, 2, …, n, are the known coefficients, bi , i = 1, 2, …, n, are the

known

right hand side values and xi, i = 1, 2, …, n are the unknowns to be determined. In matrix notation

we write the system as Ax = b

• The matrix [A | b], obtained by appending the column b to the matrix A is called the

augmented matrix.

12/5/2018 By Hailu B. 1
Cont…
• The methods of solution of the linear algebraic system of equations may be

classified as direct and iterative methods.

(a) Direct methods produce the exact solution after a finite number of steps

(disregarding the round-off errors). Gauss Elimination Method and Gauss-Jordan

Method

(b) Iterative methods are based on the idea of successive approximations. We start

with an initial approximation to the solution vector x = x0, and obtain a sequence

of approximate vectors x0, x1, ..., xk, ..., which in the limit as k → ∞, converge

to the exact solution vector x.

12/5/2018 By Hailu B. 2
Example: Direct methods Gauss
Elimination Method

12/5/2018 By Hailu B. 3
Cont…

12/5/2018 By Hailu B. 4
Direct methods: Gauss-Jordan
Method

12/5/2018 By Hailu B. 5
Cont…

12/5/2018 By Hailu B. 6
Iterative Methods Gauss-Jacobi
Iteration Method

12/5/2018 By Hailu B. 7
12/5/2018 By Hailu B. 8
Gauss-Seidel Iteration Method

12/5/2018 By Hailu B. 9
CONT…

12/5/2018 By Hailu B. 10
CONT…

12/5/2018 By Hailu B. 11
Introduction to MATLAB
• MATLAB (short for MATrix LABoratory) is a special-purpose computer
program optimized to perform engineering and scientific calculations.

• It started life as a program designed to perform matrix mathematics,


but over the years it has grown into a flexible computing system capable
of solving essentially any technical problem.

• The MATLAB program implements the MATLAB programming language


and provides a very extensive library of predefined functions to make
technical programming tasks easier and more efficient.

12/5/2018 By Hailu B. 12
The Advantages of MATLAB
• MATLAB has many advantages compared with
conventional computer languages for technical
problem solving. These include

 Ease of Use

 Predefined Functions

 MATLAB Compiler

12/5/2018 By Hailu B. 13
Disadvantages of MATLAB
• MATLAB has two principal disadvantages. The first is
that it is an interpreted language and therefore may
execute more slowly than compiled languages.
• This problem can be mitigated by properly structuring
the MATLAB program.
• The second disadvantage is cost: a full copy of
MATLAB is five to ten times more expensive than a
conventional C or Fortran compiler.

12/5/2018 By Hailu B. 14
The MATLAB Environment

12/5/2018 By Hailu B. 15
example
• As an example of a simple interactive calculation, suppose that you
want to calculate the area of a circle with a radius of 2.5 m. This can be
done in the MATLAB Command Window by typing

» area = pi * 2.5^2 =19.6350

• If the radius of the cylinder is 0.1 m and the length is 0.5 m, the volume
of the cylinder can be found using the MATLAB statements :

• » A = pi * 0.1^2

• A =0.0314

• » V = A * 0.5= 0.0157

12/5/2018 By Hailu B. 16
Exercises

12/5/2018 By Hailu B. 17
Matrix construction
• a = [1 2 3; 4 5 6; 7 8 9; 10 11 12];

12/5/2018 By Hailu B. 18
Cont…
• A = [1 3 -5 -1;-1 17 -1 -5;5 0 -1 31;1 1 1 0],
• b = [2;12;0;-11], x=A\b, error = A*x-b,

12/5/2018 By Hailu B. 19
Cont…
• In MATLAB we solve Ax = b with the single
command, x = A\b. For the example
• we compute the solution with the code
• A = [1 1 1; 2 1 3; 3 1 6];
• b = [4; 7; 2];
• x = A\b,
• x=
• 19.0000
• -7.0000
• -8.0000
Cont…
• The following code computes the LU
factorization for the example of,
A = [1 1 1; 2 1 3; 3 1 6];
[L, U, P] = lu(A),
Cont…
Thus, we have

The following code uses this LU decomposition


to solve
Example. Modeling a separation
system
• We consider a simple mass balance problem to
demonstrate the use of MATLAB to solve a system of
linear equations. For the separation system of the
Figure below, we know the inlet mass flow rate (in
kilograms per hour) and the mass fractions of each
species in the inlet (stream1) and each outlet (streams
2, 4, and 5). We wish to compute the mass flow rates
of each outlet stream.
• Here we use the notation that iF is the mass flow rate
of stream i, and iw j is the mass fraction of species j in
stream # i. We define the unknowns
Cont…
Cont…
Iterative method in MATLAB
• For the below figure calculate the values of
the unknown flow rates F1, F2 and F3 by using
any iterative Method

12/5/2018 By Hailu B. 26
Cont…

12/5/2018 By Hailu B. 27
Cont…

12/5/2018 By Hailu B. 28
12/5/2018 By Hailu B. 29
Iteration method
• F1=333.33; F2=333.33; F3=333.33
• for i=1:4;
• F1=(400-0.05*F2)/0.99;
• F2=(400-0.01*F1-0.1*F3)/0.92;
• F3=(200-0.03*F2)/0.9;
• disp([ i, F1, F2, F3])
• end

12/5/2018 By Hailu B. 30
Introduction to Plotting
• For example, suppose that we wish to plot the
function
for values of x between 0 and 10. It takes only
three statements to create this plot.
• x = 0:1:10;
• y = x.^2 – 10.*x + 15;
• plot(x,y);

12/5/2018 By Hailu B. 31
Cont…

12/5/2018 By Hailu B. 32
Using Simple xy Plots
• As we have seen previously, plotting is very easy
in MATLAB. Any pair of vectors can be plotted
versus each other as long as both vectors have
the same length.
• However, the result is not a finished product,
since there are no titles, axis labels, or grid lines
on the plot.

• Titles and axis labels can be added to a plot with


the title, xlabel, and ylabel functions.

12/5/2018 By Hailu B. 33
Cont…
• x = 0:1:10;
• y = x.^2 – 10.*x + 15;
• plot(x,y);
• title ('Plot of y = x.^2 – 10.*x + 15');
• xlabel ('x');
• ylabel ('y');
• grid on;

12/5/2018 By Hailu B. 34
Cont…

12/5/2018 By Hailu B. 35
Multiple Plots
• It is possible to plot multiple functions on the
same graph by simply including more than
one set of (x, y) values in the plot function.
• x = 0:pi/100:2*pi;
• y1 = sin(2*x);
• y2 = 2*cos(2*x);
• plot(x,y1,x,y2);

12/5/2018 By Hailu B. 36
Cont…

12/5/2018 By Hailu B. 37
Table of Plot Colors, Marker Styles,
and Line Styles

12/5/2018 By Hailu B. 38
Line Color, Line Style, Marker Style,
and Legends
• MATLAB allows a programmer to select the
color of a line to be plotted, the style of the
line to be plotted, and the type of marker to
be used for data points on the line.
• x = 0:1:10;
• y = x.^2-10.*x + 15;
• plot(x,y,'r--',x,y,'bo');

12/5/2018 By Hailu B. 39
Cont…

12/5/2018 By Hailu B. 40
Cont…
• x = 0:pi/100:2*pi;
• y1 = sin(2*x);
• y2 = 2*cos(2*x);
• plot(x,y1,'k-',x,y2,'b--');
• title ('Plot of f(x) = sin(2x) and its derivative');
• xlabel ('x');
• ylabel ('y');
• legend ('f(x)','d/dx f(x)','tl')
• grid on;

12/5/2018 By Hailu B. 41
Cont…

12/5/2018 By Hailu B. 42

Das könnte Ihnen auch gefallen