Välkomna till NUMPBIO12: DN1212 Numeriska metoder och grundläggande programmering för Bio3, 9 hp Kurshemsida http://www.csc.kth.se/dn1212/numpbio12/ 120828 DN1212 NUMPB12 1
Beatrice Frock, beatrice@kth.se (kursansvarig, numeriska metoder) Jesper Oppelstrup, jespero@kth.se (MATLAB) Övningsledare Grupp 1: Beatrice Frock Grupp 2: Arjmand Doghonay Grupp 2: Ashraful Kadir Kurslitteratur, säljs på kårbokhandeln 1. P.Pohl: Grundkurs i Numeriska metoder (GNM) 2. S.J.Chapman: Matlab Programming for Engineers (PEng) Kursbunt, xxx SEK, säljs på Matematik stud exp: kontant jämna pengar snabbare än kort! Kursprogram, Hederskodex Edsberg, Eriksson, Lindberg: Exempelsamling i numeriska metoder (EX) Laborationsuppgifter Användarhandledning för Matlab på Nada, Matlabterminologi Extentor 120828 DN1212 NUMPB12 2
Laborationer 6 obligatoriska, rapporteras i Ladok, syns i Mina sidor som LAB1 (1 + 2), LAB2 (3), LAB3 (4 + 5), LAB4 (6, = projektet). Grupper om 2. Redovisas för handledare i datorsal. Projektet redovisas normalt med skriftlig rapport. Terminalövningar i datorsal : handledare tillgängliga för konsultationer och redovisningar. Lab-arbete: ca. 160 tim = 5-7 tim eget arbete/vecka förutom schemalagd tid. Det behövs datorkonto för att köra på CSC-datorer. Delas ut nu, på F2 xxxx och TÖ1 xxxx. Vänta inte till TÖ! 120828 DN1212 NUMPB12 3
Bonus Laborationer som redovisas i tid ger bonus, max. 4 tp. Bonus-p gäller tills nästa gång kursen ges, dvs. t.o.m augusti-tentan 2013 Tentamen samma för alla DN1212,1240, -kurser Inga hjälpmedel, 3 timmar. Två delar. Godkänd del 1 ger betyget E. Del 2 rättas endast om del 1 är godkänd: E-A. Del 1: flervalsuppgifter Del 2: problemuppgifter, Matlab-program, algoritmbeskrivning. Ordinarie tenta: xxxxx Kursutvärderingsenkät I slutet av kursen. Synpunkter mottages tacksamt när som helst direkt till lärare, eller via e-mail. 120828 DN1212 NUMPB12 4
VECKA 35 27/8 F1 Introduktion. MATLAB. PEng 1-2 28/8 F2 Styrstrukturer, programmeringsteknik, PEng 3-4 Ö1 Programmering, PEng 2.1, 2.6, 2.10, 2.16 (2.14) 30/8 TÖ1 Kursreg. via Rapp. Arbete med och redovisning av Lab 1 31/8 Ö2 Programmering, PEng 3.3, 3.7, 4.7a,4.8a, 4.9a, 4.19 VECKA 36 3/9 F3 Funktioner, PEng 5 4/9 F4 Datastrukturer, PEng 6-7 Ö3 Programmering, PEng 5.2, 5.9, 5.22, (5.17), 5.28 (5.24) 5/9 TÖ2 Arbete Lab 2 6/9 Ö4 Programmering, PEng 6.12, 6.11, 6.22, 7.3, kontoregister TÖ3 Arbete Lab2 VECKA 37 10/9 Ö5 Programmering, PEng 9.1, 9.6, 10.2. 10.15 11/9 F5 Grafiska användargränssnitt. PEng 9 10 12/9 TÖ4 Deadline bonus Lab 2, arbete Lab 3 13/9 F6 Filhantering, PEng 8 Ö6 Programmering, PEng 8.1, 8.8, 8.12, 8.11 i 14/9 TÖ5 Arbete med eller redovisning av Lab 3. Påbörja Lab 4 120828 DN1212 NUMPB12 5
It is hard to understand... an ocean because it is too big. a molecule because it is too small. nuclear physics because it is too fast. the greenhouse effect because it is too slow. [Super] Computers break these barriers to understanding. They, in effect, shrink oceans, zoom in on molecules, slow down physics, and fast-forward climates. Clearly a scientist who can see natural phenomena at the right size and the right speed learns more than one who is faced with a blur. Vem, när? 120828 DN1212 NUMPB12 6
The purpose of computing is insight, not numbers. (R.W.Hamming) The Unreasonable Effectiveness of Mathematics (1980) There are three kinds of lies: Lies, damn lies, and colorful computer pictures (P.Colella) B.Disraeli, M.Twain 120828 DN1212 NUMPB12 7
Nr. 1 June 2012: US LLNL BlueGéne Q 1.5 M cores 16 000 TF,... not Nr. 76 June 2012 120828 DN1212 NUMPB12 8
Helt dominerande program för ingenjörsberäkningar, numerisk analys, visualisering, 1974 Matrix Laboratory C.Moler Nu: MathWorks > 2200 pers. MATLAB 20-årsdag 2004: Varför MATLAB? Life is too short for writing do-loops C.Moler, 1974 120828 DN1212 NUMPB12 9
http://www.ima.umn.edu/~arnold/disasters/disasters.htm Have you been paying attention in your numerical analysis [...] courses? If not, it could be a costly mistake. Here are some real life examples...: The Patriot Missile failure, in Dharan, Saudi Arabia, February 25, 1991... poor handling of rounding errors. The explosion of the Ariane 5 rocket just after lift-off on its maiden voyage off French Guiana, on June 4, 1996,... the consequence of a simple overflow. The sinking of the Sleipner A offshore platform in Gandsfjorden near Stavanger, Norway, on August 23, 1991,... the result of inaccurate finite element analysis. 120828 DN1212 NUMPB12 10
MATLAB 1 rad: x = A\b; F77 50 rader... call msolve(n,a,rhs,sol)... subroutine msolve(n,a,b,x) implicit none integer n real*8 A(n,n),b(n),x(n) do i=1,n c Search for pivot element col = i row = i do j=i,n do k=i,n if(abs(a(p(k),q(j))).gt. abs(a(p(row),q(col)))) then row = k col = j endif enddo c end enddo Swap diagonal element with found pivot k = p(i) Intel x86 assembler 500 rader.file.section "msolve.f".rodata.str1.1,"ams",@progbits,1 120828 DN1212 NUMPB12 11.LC0:.L4:.string "Memory allocation failed".text.globl msolve_.type msolve_, @function msolve_: pushl %ebp %esp, %ebp pushl %edi pushl %esi pushl %ebx subl $108, %esp 8(%ebp), %ebx 12(%ebp), %eax 16(%ebp), %edx 20(%ebp), %ecx (%ebx), %esi %eax, -76(%ebp) %edx, -80(%ebp) %ecx, -84(%ebp) %esi, %eax notl %eax sarl $31, %eax andl %eax, %esi %esi, -20(%ebp) -20(%ebp), %eax notl %esi %esi, -56(%ebp) $0, -44(%ebp) sall $2, %eax je.l4 subl $12, %esp pushl %eax call malloc addl $16, %esp testl %eax, %eax %eax, -44(%ebp) je.l39 notl %ea (%ebx), %edx $0, -40(%ebp) %edx, %eax
MATLAB: (s = 3;) s = s + 2; PowerPC Assembler LD r14,[s] ADDI r14,r14,2 ST [s],r14 Minne 0 0 Nr. 102679 Minnesplats för s ( symbolisk adress ) Fysisk adress: 102679 3 CPU-register 5 r15 r14 r13 120828 DN1212 NUMPB12 12
Sverige Germund Dahlquist 1925-2005, KTH Svante Littmarck, Dr HC, KTH Huvudkontor Boston:150 Utveckling:Stockholm: 40 120828 DN1212 NUMPB12 13
ALGORITM Wikipedia: In mathematics and computer science, an algorithm ([ ] Muḥammad ibn Mūsā al-khwārizmī) is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning. A = 39; B = 4; while B ~= 0 if A > B A = A - B else B = B - A end end GCD = A - Fullst. beskrivning - Ändligt antal steg - Alla fall täcks in - Formalia: MATLAB 120828 DN1212 NUMPB12 14
Matematik, kontinuitet, reella tal, intervallhalvering: Om f är kontinuerlig på [a,b], f(a) < f(b), så finns för varje y, f(a) < y < f(b), ett x så att f(x) = y f = @(x) 3*sin(x)-0.5*x % matlabsyntax, senare a = 0; b = 1; % f(a) = 0, f(b) = 2 (ca.) y = 1.5; % vilket x ger f(x)= y? a < x < b %--------------------------------------------------------- while 1>0 % abs(a-b) > 1e-6 c = (a+b)/2; if f(c) > y % c upper bound, move b down to c b = c else % c lower bound, move a up to c a = c end end Tips: Algoritmen kan användas i Lab 1, Pumpa-gissning / Datorn gissar 120828 DN1212 NUMPB12 15
Kan man avgöra om en algoritm slutar? - Euklides, Intervallhalvering, Ja - Det finns ingen algoritm som avgör om en given algoritm slutar - Turing, Gödel, m fl. 120828 DN1212 NUMPB12 16