22
2008 Computing for the Physical and Social Sciences Ken Steiglitz

COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

Page 1: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

COS 323 Fall 2008

Computing for the Physical and Social Sciences

Ken Steiglitz

Page 2: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Mechanics and course structure

• See course web page: COS 323 home

• Syllabus: lecture outlines, slides (some courtesy of Prof. Szymon Rusinkiewicz),

some detailed notes, etc.

• Master list of references in pdf, some on reserve in library

Page 3: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Goal of course: learn “scientific” computing through applications

• 4 assignments: population genetics, finance, chaos, image processing

• Term paper

Page 4: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Major Topic Outline

• Simulation, using random numbers, experimenting

• Integration, root-finding• Optimization, linear programming• Ordinary diff. eqs., Partial diff. eqs.• DSP• Linear systems, image processing

(Matlab)

Assign. 1

Assign. 2

Assign. 3

Assign. 4

Page 5: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Major Topic Outline

• Simulation, using random numbers, experimenting

• Integration, root-finding• Optimization, linear programming• Ordinary diff. eqs., Partial diff. eqs.• DSP• Linear systems, image processing

(Matlab)

* Numerical analysis

Assign. 1

Assign. 2

Assign. 3

Assign. 4

Page 6: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

“Personal” vs. “Scientific” computing

• Early computers, up to the 70s or 80s, were built to solve problems. They were “scientific computers”, or SCs, so to speak

• Today the vast majority of computers are PCs

Page 7: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

What this course is about

• PC: Cycles used mainly for fixed, widely used programs, for communication, rendering, DSP, etc.

• SC: Involves developing programs: programming, modeling, experimentation

Machines are driven by the mass market

Page 8: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Stanisław Ulam with MANIC I --- about 104 ops/sec

Page 9: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz
Page 10: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Reading, background• Optional text: http://www.nr.com Numerical

Recipes in C [PTVF92]. Really a reference available on web

• Master reference list

• COS 126 is entirely adequate, don't get too fancy --- We're after the algorithmic and numerical issues

• MAT 104 is entirely adequate

• Referencing all sources: Do it!

Page 11: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Modeling in general

• Purposes: quantitative prediction, qualitative prediction, development of intuition, theory formation, theory testing

• Independent and dependent variables, space, time

• Discrete vs. continuous choices for space, time, dependent variables

• Philosophy: painting vs. photography

Page 12: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Examples

• Discrete-time/discrete-space/discrete-value spatial epidemic models

Sugarscape seashells lattice gasses cellular automata in general

Page 13: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Examples, con’t

• Difference equations

population growth

population genetics

digital signal processing,

digital filters, FFT, etc.

Page 14: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Examples, con’t

• Event-driven simulation

market dynamics

population genetics

network traffic

Page 15: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Examples, con’t• Ordinary differential equations

market dynamics epidemics seashells insulin-glucose regulation immune system predator-prey system n-body problem, solar system, formation of galaxy

Page 16: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Examples, con’t

• Partial differential equations

heat diffusion

population dispersion

wave motion in water, ether, earth, …

spread of genes in population

classical mechanics

quantum mechanics

Page 17: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Examples, con’t

• Combinatorial optimization

scheduling

routing, traffic

oil refining

layout

partition … and many more

Page 18: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Numbers• Fixed-point (absolute precision)• Floating-point (relative precision) scientific notation, like 3x10-8

• Single-precision: 32 bits, 8 bit exponent, about 7 decimal-place accuracy• Double-precision: 64 bits, 11 bit exponent, about 16 decimal-place accuracy

[see IEEE 754 standard]

Page 19: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Numbers (con’t)

Example: 1/10 has no exact representation in binary floating-point:

main(){ /* main */float x;x = 1./10.;printf("x = %28.25f\n", x);}

x = 0.1000000014901161193847656

Page 20: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Numbers (con’t)Such roundoff errors can accumulate in

iterative computations:main(){ /* main */float x, sum;int i;x = 1./10.;sum = 0.;for (i=0;i<10000000;i++) sum += x;printf("sum = %28.25f\n", sum);}

sum = 1087937.0000000000000000000000000

Page 21: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

More subtle problem

Roots of quadratic:

Relative error in x1 is huge!

What’s the problem?

main(){ /* main */printf("Solving quadratic\n");printf("Actual root = 0.00010...\n");printf("Actual root = 9998.9...\n");float a, b, c, d, x1, x2;a = 1.;b = -9999.;c = 1.;d = b*b - 4.*a*c;x1 = (-b + sqrt(d))/2.;x2 = (-b - sqrt(d))/2.;printf("x1= %28.25f\nx2= %28.25f\n", x1, x2);}

Solving quadraticActual root = 0.00010...Actual root = 9998.9...x1= 9999.0000000000000000000000000x2= 0.0000250025004788767546415

X2 – 9999 x + 1 = 0

Page 22: COS 323 Fall 2008 Computing for the Physical and Social Sciences Ken Steiglitz

Higher-level languagessuch as Matlab, Maple, Mathematica

|\^/| Maple V Release 5 (WMI Campus Wide License)._|\| |/|_. Copyright (c) 1981-1997 by Waterloo Maple Inc. All rights \ MAPLE / reserved. Maple and Maple V are registered trademarks of <____ ____> Waterloo Maple Inc. | Type ? for help.# solving ill-conditioned quadratic# x^2 -9999*x+1 = 0# b := -9999.x1 := ( -b - sqrt(b*b - 4) )/2; Digits := 7 x1 := 0 Digits := 8 x1 := .0001 Digits := 20 x1 := .0001000100020004 Digits := 40 x1 := .000100010002000400090021005101270323

Mutiple-precision arithmetic(software)

Experimental technique