Introduction To Matrix: A11x1 + A12x2 + ... + A1nxn b1 A21x1 + A22x2 + ... + A2nxn b2
Introduction To Matrix: A11x1 + A12x2 + ... + A1nxn b1 A21x1 + A22x2 + ... + A2nxn b2
known
right hand side values and xi, i = 1, 2, …, n are the unknowns to be determined. In matrix notation
• 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
(a) Direct methods produce the exact solution after a finite number of steps
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
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.
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
• 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
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.
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