288x Filetype PDF File size 0.70 MB Source: download.atlantis-press.com
Proceedings of the 2012 2nd International Conference on Computer and Information Application (ICCIA 2012)
An Application of MATLAB in practical problems
XIE Huiyang Bi Qiuxiang
College of Sciences Fixed-Income Department
Beijing Forestry University GF securities CO., LTD
Beijing, China Guangzhou, China
xhyang@bjfu.edu.cn gfbqx@tom.com
121 101
Abstract—This article gives an example of using Matlab to
solve practical problems
AB==012, 022
Let ,
Keywords-Linear Algebra; Matlab
364 351
I. INTRODUCTION calculate AB , A1B.
Matlab(Matrix Laboratory) is a commercial
mathematical software developed by MathWorks for >> A = [1 2 -1; 0 1 2; -3 6 4];
numerical computation. One of the nice features of Matlab >> B = [-1 0 1; 0 2 2; 3 5 1];
is its ease of computations with vectors and matrices. >> A * B
Matrix operations, numerical analysis, signal processing, Result of AB returned:
graphics, and user interface creation can be easily ans =
manipulated in Matlab. It also provides many -4 -1 4
implementations of algorithms and interface to other 6 12 4
programming language. With help of additional toolboxes 15 32 13
and package, Matlab even supports symbolic computation, >> inv(A) * B
graphics manipulation and model-base designing for A1B
dynamic and embedded systems. Result of returned:
Matlab is widely used in all areas of science and ans =
technology in education and research at universities. Many -1.0000 0.1304 1.3478
courses of mathematics and engineering are using Matlab 0 0.3478 0.2609
for education on campus. 0 0.8261 0.8696
Linear algebra is a branch of mathematics, which is (The numbers could be expressed as fractions either.)
central to modern mathematics and incredibly useful in the
modern world. It plays important roles in the researches of Sample 2.
mathematics, mechanics, physics and other subjects, and it Find the solution of equations
is widely applied to solve the real world problems. For +++=
xxxx
22 0
most non-linear problems, the usual method is to 1234
approximate them by linear problems. People are only +=
xxxx
2220
really good at solving linear problems by now due to the 1234
=
xxxx
development and widespread use of the computer in areas 430
that apply mathematics. By using Matlab, the complicated 1234.
calculations could be avoided. With Matlab, we can utilize
linear algebra into real life to solve practical problems. In >> A = [1 2 2 1; 2 1 -2 -2; 1 -1 -4 -3];
the past two decades, the applications of linear algebra to
real world problems have mushroomed. In this paper, >> format rat // Let the solution outputs in the
some examples on solving linear problems with Matlab are rational form.
illuminated and how to use Matlab in practice is discussed. >> B = null(A, 'r') // Get the rational basis of space
A.
APPLICATION IN LINEAR ALGEBRA OPERATIONS B =
II. 2 5/3
Linear algebra operations such as Matrix -2 -4/3
multiplication, finding inverse of a matrix, solving a 1 0
system of linear equations and diagonalizing quadratic 0 1
forms would lead to boring and complicated calculations. The column vectors in B form the basic set of
However, these operations can be performed very simply solutions. Apply the following commands to get the
using matlab. general solution.
Sample 1.
>> syms k1 k2 // define the symbols k1 and k2
>> X = k1 * B(: , 1) + k2 * B(: , 2) // write the
general solution
Published by Atlantis Press, Paris, France.
© the authors
1631
Proceedings of the 2012 2nd International Conference on Computer and Information Application (ICCIA 2012)
>> pretty(X) // make X >> zeroelement(1, 3)
more pretty >> zeroelement(1, 4)
>> wamparray(2, 3)
We usually reduce coefficient matrix into row echelon >> zeroelement(2, 3)
form to use general solution to solve linear equations. >> zeroelement(2, 4)
Command “rref” would provide row echelon form matrix >> zeroelement(3, 4)
in Matlab.
Each step implemented, the result will be displayed to
>> B = rref(A) help users observe. You can attach a semicolon at the end
B = of the row to omit the intermediate output.
-5/3 1 0 -2 III. APPLICATION IN SOLVING PRACTICAL PROBLEMS
4/3 0 1 2
0 0 0 0 Sample 1. There’re five cities with its own airport and
some one-way airlines between the cities. As figure i
To observe intermediate data, sometimes, the shows, a directed edge from node A to node B represents
user-defined functions are needed, showing the an airline from city A to city B.
information expected. In sample 3, reducing matrix to its
row echelon form is implemented by user-defined M
function.
Sample 3.
14115
Figure i
2867
A= The cities and the airlines could be represented by an
32128 adjacency matrix . If there’s an airline from city
A=()a
ij
715660
i to city j, let a =1, otherwise a =0. Figure I can be
Let , get the row echelon ij ij
form of A. represented as matrix A.
01101
We will program two M-functions for the intermediate
data. Given the matrix A and row index i and column
10011
index j, the M-function named zeroelement.m is going to
A=
a =0 a ≠0 10010
reduce A by making ij , when ii and
i < j 01100
.
function [A]= zeroelement(A, i, j) 01000
if i>j | i==j
error('i is not less than j') In A2 , aij is the number of route from city i to city j
else though exact one transfer. Enter the following commands
A(j, :)=A(j, :)-A(i, :)*(A(j, i)/A(i, i)); in Matlab.
end A=[0,1,1,0,1;1,0,0,1,1;1,0,0,1,0;0,1,1,0,0;0,1,0,0,0]
A1*= AA
The other function named swaparray.m will swap the A1 =
i-th row and j-th row in A.
2 1 0 2 1
function [A] = swaparray(A, i, j)
if i>n|j>n 0 3 2 0 1
error('out of range')
else 0 2 2 0 1
temp1=A(i, :);
temp2=A(j, :); 2 0 0 2 1
A(i, :)=temp2;
A(j, :)=temp1; 1 0 0 1 1
end Let’s take an element in A1 for verification. A1[2][3] =
2 means there’re two different strategies to reach city 3
Invoking these functions repeatedly, we’ll finally get from city 2 though a transfer. Enumerating all the paths,
the row echelon form of matrix A. we can find exactly two ways which are 2→4→3,
2→1→3.
>> A=[1 4 11 5; 2 8 6 7; 3 2 12 8; 1 15 66 0]; The matrix keeps the number of routes between each
>> zeroelement(1, 2)
Published by Atlantis Press, Paris, France.
© the authors
1632
Proceedings of the 2012 2nd International Conference on Computer and Information Application (ICCIA 2012)
two cities though at most one transfer could be simply 1
2
10
described as B =+AA. Enter the command
a 2
BA=+A1 n
in Matlab. () 1
n
,01
XbM
B = ==
n
2 2 1 2 2 2
c
n
000
1 3 2 1 2
1 2 2 1 1
()nn(1) ()nn(0)
2 1 1 2 1 X =MX X =MX
There’re three eigenvalues to matrix M, so M can be
1 1 0 1 1 diagonalized which means there is a diagonal matrix D and
Rest can be deduced by analogy. a invertible matrix P satisfy M = PDP1 .So
Sample 2. ()nn1 (0)
XP= DPX
In autosomal genetic, individual inherits one gene for should be satisfied. The diagonal
each gene pair from its parents to form its own unique elements in D are the eigenvalues of M and P is the
gene pairs. The inherited gene is selected randomly. If a eigenvector correspondingly.
parent has gene pair Aa, the descendant will have the same First of all, we’ll calculate the eigenvalues and
probabilities to inherit gene A or gene a. For a parent with eigenvector of M.
gene pair aa and another with gene pair Aa, the descendant >> A = [1 0.5 0;0 0.5 1;0 0 0];
can be with gene pair Aa or aa in the same probability. >> [P, D] = eig(A); // eigenvalues and eigenvector of
Enumerating all the parents gene pairs, the probabilities of matrix A
1 0.7071 0.4082 1 0 0
each case are listed below.
PD=0 0.7071 0.8165 , =0 0.5 0
Parents’ gene pairs
0 0 0.4082 0 0 0
AAA a AaA a aaaa ,
AAA A AAa a Aaa a Combined with the results returned, the distributions at
each generation can be calculated by
s DescenAA 1 1/2 0 1/4 0 0
gene a
0
Aa (0)
Xb
d 0 1/2 1 1/2 1/2 0 = 0
p a
ai nt’ ()nn1 (0)
r aa c
0
XP= DPX
0 0 0 1/4 1/2 1 , with and
ab++c=1
There’re some crops consist of three 000. The multiplication of matrix in Matlab is
genotypes based on a certain distribution. All helpful here.
AAA,,aaa
the crops are pollinated by the crops with AA genotype. UMMARY
S
Let ab,,c be the portion of crops with Linear algebra is an efficient tool to help do scientific
nnn
genotype in n-th generation. . calculations on immense amounts of data, especially when
AAA,,aaa (0n = ,1,2) it is combined with computers. This article gives some
ab,,c are the original distribution and examples to demonstrate the advantages of using Matlab
000 in linear algebra. Teaching linear algebra with Matlab not
satisfying . The n-th generation distribution
ab++c=1
000 only enhances students’ learning interest, but also
satisfies the following equations. improves their ability of applying theories to solve
1 practical problems.
aa=+b
nn11n
2 CKNOWLEDGMENT
1 A
bc=+b Funded projects: (863) "large number DNA
nn11n
2 decomposition computer model research project (Code:
c =0 2009AA01Z413)
n
EFERENCES
Let R
[1] Chen Huaichen, Gong Jiemin, and MATLAB introductory linear
algebra practice (Second Edition), publishing house of electronics
industry, 2009
[2] Zhou Jianxing, will Tsu Take, MATLAB Xingming, from entry to
the master, the people post and Telecommunications Press, 2008
Ḥ
Published by Atlantis Press, Paris, France.
© the authors
1633
no reviews yet
Please Login to review.