Title: MATLAB MATRIX LABORATORY
1????? ???????? ?????? ???? ???"? (2)
????? ??' 1
??? ?''? ?????? ????????
2??????
- 1. ??????? ????? ??????? ??????? ????????.
?????? ??????, ????? ??????? ??????? ????. - 2. ????? ?????? ?????, ????? ?????? ??????, ???
????? programming tool. ????? ??????????? ???????
????? - 3. ?????? ??????? ???''? ????? ?????? ?????.
???? ??- ???-?????. ???? ????????? ???????? ?????
???????. ????? ?????? ???????. ???????????
??????? (????? ?????? ????? ??????) - 4. ?????? ???????????? ?????????? ???????.
??????? ?????. ????? ?? ??????????? ??????. ?????
?? ????????? ??????. - 5. ???? ?????? ?????? ??????? ???????. ????? ??
????? ??????, ??? ????? ?????? ???????? ????????. - 6. ??? ????? ??? ???''?. ?????? ??????
?????????. ???????? ??????? ?? ???? ???, ???????
????????.
- 7. ???? ???????? ???????. ??????
- ??????.
- 8. ????? ???????? '????' ???????
- ???????? ???????? ???????? ?????
- '????'.
- ????? ??????. ????? '????- ?????' ,
- ?????? ?? ????? ?????? ??????.
- 10. ?????? ?????? ????? ?????? ??????
- ?? ???????-????? ??????-??????,
- ????????? ?? ????????? ???-???.
- ?????
- Charles F. Van Loan. Introduction to Scientific
Computing A Matrix-vector Approach using Matlab.
Prentice-Hall, 2000. - C. Moler. Numerical Computing with Matlab. SIAM,
2004. - Adrian Brian, Moshe Breiner. Matlab 6 for
Engineers. Prentice-Hall, 2005.
3?????
- ?????? ?????? ??????????? ??????? ??????? ???????
???????? ???''?. ????? ?????? ??????? - -????? ???????? ???????
- -????????? ??????????? ???????????
- -????? ???? ????? ??????
- -?????? ???????? ???????
- -????? ????? ????? ?????
- ?????? ????? ??????? ?????? ????? ???? ??????
??????? ??????? ?????. -
You never stop using Mathematical Software
4??????? ???? ????? ?????? ?????
Quality assurance is a process for enhancing the
reliability of the technical data, uses for these
purposes various mathematical models and
calculations. Basis of this calculations is
numerical analysis realized on the computers with
special mathematical/statistical
software. Mathematical software (MS) is a type
of software which has mathematical and
statistical components. MS is designed
to solve classical algebra and differential
equations and problems in human readable
notation. Software such as Mathcad Matlab Mat
hematica Maple
5??????, ??????? ????????
Computer realization of the model is writing
the algorithm for numeric/graphical solution in
special codes with further verification of both
the codes and the algorithm. Codes are sequence
of commands in a programming language Programmin
g language is vocabulary and codes through which
one is able to give an operational command to the
computer Algorithm is step-by-step
problem-solving procedure/s used within software
applications Commands and procedures used in
different programs and are varied with software
we study firstly the the procedures in
mathematical softwares Mathcad, Matlab, and in
simulation software Arena
6?????? ???????? ???????
- ?????? ????? ??????? ????????
Insufficient spatial and temporal discretization
Insufficient iterative convergence
Computer Round-off/ Truncation
Computer Programming (input, output, codes,
numeric algorithm,compiler, operating system)
7?????? ???????? ???????
- ????? ??-?????? - DISCRETIZATION
- (Taylor Series
Expansion ) - result of construction of finite-difference
formula
xi1
xia
x
8?????? ???????? ???????
Discretization error (Taylor Series Expansion )
9?????? ???????? ???????(????)
- Computer Arithmetic
- Computers use a base 2 (binary) representation of
numbers with a finite number of digits. This
approach has limitations, but works well in
general when the representation is large enough,
i.e. when enough digits are used. - What do the digits in a base 10 number represent?
- 1234(Base 10) 11032 1023 1014 100
- How about a base 2 number?
- 1011(Base 2) 1 230 221 211 20 821
11(Base 10) - Example Compute the base 10 and base 2
representations of 1234 - Base 10 1234 1.234 103
1103210231014100 - Base 2 1234 102412864162
- 1210127126124121
- 1234(Base 10) 10011010010(Base 2)
Computer Round-off/ Truncation
10?????? ???????? ???????(????2)
????? ?????? (10???? )
????? ?????? (2 ????)
For 8-bit, 28 256 quantities (integers,
real numbers or text) For 16-bit, 216 65536
quantities
11?????? ???????? ???????(????3)
Converting decimal to binary
- To convert a decimal integer into binary, keep
dividing by 2 until the quotient is 0. Collect
the remainders in reverse order. - To convert a fraction, keep multiplying the
fractional part by 2 until it becomes 0. Collect
the integer parts in forward order. - 162.375 ??????
-
- 162.37510 10100010.0112
12?????? ???????? ???????(????4)
13????? ????? ?????? ?????
- ?????? ??????? ????? ?? ????? 2 ?? ???? ???? ??
?????. ??? ???? ?????? ??? ???? ??? ?? ????? - ??????? ?????? ??????
- ?? ????? 1234 ????? 10 ???? ????? ????? ????
- 1234(10 ????) 1103210231014100
- ??? ??????
- 9141.25 9103110241011100210-1510-2
- ???? ???? ????? ????? 2
- 1011(2 ????) 123022121120 821
11(10 ????) - ??? ??????
- 00111001.11010001 251 241 231 201
2-11 2-21 2-4 - ???? ?? ????? 132 ?????
- ???? ?? ????? ?????? 132 ????? ???????
- 132d 2722 (1284132)
- ??????? ?????? ?????? ??? ??????? (????? ?????)
?? ????? ????? ?-1 -
- 132d 1000100b
14????? ????? ?????? ?????
- Real numbers that are not a sum of powers of two
cannot be exactly represented (like 1/3 in base
10) that leads to truncation error (???? ????? ) - The finite representation can lead also to errors
called rounding errors (???? ????? ) - Real numbers (infinite precision) can be
translated into finite precision in two ways by
truncation or rounding, a. e. - Exact Value 3.14159265
- Truncated value 3.141592 Error 0.00000065
- Rounded value 3.141593 Error 0.00000035
- 32-bit (2 byte, single precision) machine
7 digits - 64-bit (4 byte, double precision) machine 17
digits - ???? (23 ?????) ???? (8 ?????)
Computer Round-off/ Truncation Errors
15?????? ???????? ???????(????). ????? ?????????Â
Significant Digits
- ???? ???????? ??? ????? ???? ???? ????? ?????
- 32-bit (2 byte, single precision) machine 7
significant digits - 64-bit (4 byte, double precision) machine 17
significant digits
8-bit word
False Significant Figures
3.25/1.96 1.65816326530162... (from MATLAB) But
in practice only report 1.65 (truncation) or 1.66
(rounding)! Why??
Because we dont know what is beyond the second
decimal place
16?????? ???????? ??????? (????)
Truncation Error
- ????? ?????
- ??????
- ????? ?????? ???? ????
17?????? ???????? ??????? (????)
Truncation Error
function term, sum exponential Evaluate
exponential function exp(x) by Taylor series
expansion f(x)1 x x2/2! x3/3! ...
xn/n! clear all x input('enter the value of x
') n input('enter the order n ') term(1)
1 sum(1) term(1) for i1n term(i1)
term(i)x/i sum(i1) sum(i)
term(i1) end Display the results disp(' i
term(i) sum(i)') a 1n1
outputa' term' sum' fprintf('4d 15.8f
15.8f \n',output')
18?????? ???????? ??????? (????)
- How does a computer represent a real number x?
- x 0.qBe
- q is called the mantissa and is a number
(specifically a fraction). - B is base (2 or 10)
- e is called the characteristic.
- The sign of the number must also be represented.
-
- In addition, the finite representation can lead
to errors in calculations called rounding errors. - Real numbers (infinite precision) can be
translated into finite precision in two ways - by truncation or rounding.
- Exact Value 3.14159265
- Truncation 3.141592
- Rounding 3.141593
19?????? ???????? ??????? (????)
10951467 (base B 10) mantissa q
-(110-1 410-2 610-3 710-4 )
-0.1467 signed exponent n (9101 5100)
95
20????? ????? ?????? ?????
- ?????? ??????? ????? ?? ????? 2 ?? ???? ???? ??
?????. ??? ???? ?????? ??? ???? ??? ?? ????? - ??????? ?????? ??????
- ?? ????? 1234 ????? 10 ???? ????? ????? ????
- 1234(10 ????) 1103210231014100
- ??? ??????
- 9141.25 9103110241011100210-1510-2
- ???? ???? ????? ????? 2
- 1011(2 ????) 123022121120 821
11(10 ????) - ??? ??????
- 00111001.11010001 251 241 231 201
2-11 2-21 2-4 - ???? ?? ????? 132 ?????
- ???? ?? ????? ?????? 132 ????? ???????
- 132d 2722 (1284132)
- ??????? ?????? ?????? ??? ??????? (????? ?????)
?? ????? ????? ?-1 -
- 132d 1000100b
21????? ????? ?????? ?????
- Real numbers that are not a sum of powers of two
cannot be exactly represented (like 1/3 in base
10) that leads to truncation error (???? ????? ) - The finite representation can lead also to errors
called rounding errors (???? ????? ) - Real numbers (infinite precision) can be
translated into finite precision in two ways by
truncation or rounding, a. e. - Exact Value 3.14159265
- Truncated value 3.141592 Error 0.00000065
- Rounded value 3.141593 Error 0.00000035
- 32-bit (2 byte, single precision) machine
7 digits - 64-bit (4 byte, double precision) machine 17
digits - ???? (23 ?????) ???? (8 ?????)
Computer Round-off/ Truncation Errors
22?????? ???????? ???????(????)
23?????? ???????? ???????(????)
- gtgt x120
- sroundn(sqrt(x),-4) roundn - from Mapping
toolbox - - troundn(sqrt(x)./3,-4)rounding up to 4
digits after the point - format short e
- sdoublesqrt(s)
- tdoublesqrt(t)/3
- errorsabs(s- sdouble) absolute error in
s - errortabs(t- tdouble) absolute error in t
- relative error in st and in s-t
- Rserrors./sdouble relative error in s
- Rterrort./tdouble relative error in t
- RsyRsRt
- RsminusyRs./(s-t)Rt./(s-t)
- s' sdouble' errors' t' tdouble' errort' Rsy'
Rsminusy' - plot(x, Rsminusy,-o,x, Rsy,d),grid,
- legend(s-t,st)
- 1.0000 1.0000 0 0.3333 0.1924
0.1409 - 1.4142 1.1892 0.2250
0.4714 0.2289 0.2425
24????????? ??????? ?????? ??????? ???????? ???????
- ?????? ?? Patriot
- Software Problem Led to System Failure at
Dhahran, Saudi Arabia - The cause was an inaccurate calculation of the
time since boot due to computer arithmetic errors
Specifically, the time in tenths of second as
measured by the system's internal clock was
multiplied by 1/10 to produce the time in
seconds. This calculation was performed using a
24 bit fixed point register. The small
truncation error, when multiplied by the large
number giving the time in tenths of a second, led
to a significant error. Indeed, the Patriot
battery had been up around 100 hours,
25????????? ??????? ?????? ??????? ???????? ???????
0.1 is 0.000110011001100110
0110011001100.... Now, in the 24 bit register of
Patriot this number stored as
0.00011001100110011001100 Thus truncation error
is 0.0000000000000000000000011001100.
.. or about 0.000000095 decimal.
Multiplying by the number of tenths of a second
in 100 hours gives Total error
0.0000000951006060100.34 sec A Scud travels
at about 1,676 meters per second, and so travels
more than half a kilometer in this time. This was
far enough that the incoming Scud was outside the
"range gate" that the Patriot tracked.
26????????? ??????? ?????? ??????? ???????? ???????
(????)
- ????? ?- Ariane 5
- On June 4, 1996 an unmanned Ariane 5 rocket
launched by the European Space Agency exploded
just forty seconds after its lift-off from
Kourou, French Guiana.
The cause of the failure was a software error in
the inertial reference system. A 64 bit floating
point number relating to the horizontal velocity
of the rocket with respect to the platform was
converted to a 16 bit signed integer. The number
was larger than 32,767, the largest integer
storeable in a 16 bit signed integer, and thus
the conversion failed.
27????????? ??????? ?????? ??????? ???????? ???????
(????2)
- Parliamentary elections in Schleswig-Holstein
- Rounding error changes Parliament makeup in
Germany (1992)
In German parliamentary elections, a party with
less than 5.0 of  the vote cannot be seated.Â
The Greens appeared to have a cliff-hanging
5.0, until it was discovered (after the results
had  been announced) that they really had only
4.97. The printout was two figures, and the
actual percentage was rounded to 5.0.