La présentation est en train de télécharger. S'il vous plaît, attendez

La présentation est en train de télécharger. S'il vous plaît, attendez

Finite Precision Computation ( ). num=0; EPS=1; while (1+EPS)>1 EPS=EPS/2; num=num+1; end x=zeros(1,10); for n=1:10 x(n)=sin(n*pi/10); end EPS=1; for.

Présentations similaires


Présentation au sujet: "Finite Precision Computation ( ). num=0; EPS=1; while (1+EPS)>1 EPS=EPS/2; num=num+1; end x=zeros(1,10); for n=1:10 x(n)=sin(n*pi/10); end EPS=1; for."— Transcription de la présentation:

1 Finite Precision Computation ( )

2 num=0; EPS=1; while (1+EPS)>1 EPS=EPS/2; num=num+1; end x=zeros(1,10); for n=1:10 x(n)=sin(n*pi/10); end EPS=1; for num=1:1000 EPS=EPS/2; if (1+EPS)<=1 EPS=EPS*2 Break End end

3 for variable=expression Statements end while expression Statements end If expression Statements end switch x case 1 statement1 case statement2 otherwise end == ~= & | ~ XOR Matlab % … x=zeros(1,10); for n=1:10 x(n)=sin(n*pi/10); end num=0; EPS=1; while (1+EPS)>1 EPS=EPS/2; num=num+1; end EPS=1; for num=1:1000 EPS=EPS/2; if (1+EPS)<=1 EPS=EPS*2 break end

4 g=2; for k=1:100 g=1+1/g; end g function yprime = lorenzeq(t,y) yprime = [ 10*( y(2)-y(1) ) 28*y(1) -y(2) -y(1)*y(3) y(1)*y(2) -8/3 *y(3) ]; %ODE solver t = [0 50];y0= [0;1;0]; [t,y] = ode45('lorenzeq',t,y0); plot( y(:,1),y(:,3) ); xlabel('y_1');ylabel('y_2'); title( 'Lorenz equations','FontSize',16)

5 2^(1-53) ans = 2.220446049250313e-016 xmin=2^(-1021-1) xmin = 2.225073858507201e-308 xmin=2^(-1021-1-52) xmin = 4.940656458412465e-324 eps=2.220446049250313e-016 realmax=1.797693134862316e+308; realmin=2.225073858507201e-308; 1.1*realmax=Inf; 0/0=NaN; inf/inf=NaN; realmin*eps=4.940656458412465e-324; realmin*eps*0.1=0; MATLAB double precision (64-bit word) 16 significant decimal digits F(2,53,-1021,1024,true)

6 a=1; b=1; while a+b~=a b=b/2; end a=1.0e+308; b=1.1e+308; c=-1.001e+308; a+(b+c) a+b+c %numerical cancellation x=1.e-15; ((1+x)-1)/x

7 Chaque calcul simple est ensuite fait au mieux : le processeur renvoie le meilleur resultat possible (norme IEEE-754), etant donnes ses imperatifs. 3.14 2 = 9.859 6 9.86 Chaque resultat de calcul est donc arrondi. M^eme si un calcul est presque juste, une succession de calculs est parfois fausse : π 2 3.14 2 = 9.859 6 9.86 Mais π 2 = 9.869 604 … donc le nombre ottant le plus proche est 9.87

8

9

10

11 Orientation de 3 points (G. Melquiond) Etant donnes 3 points du plan p, q et r. On veut savoir si pqr sont alignes dans le sens horaire ou dans le sens anti-horaire. float det = ( qx - px ) * ( r y - py ) - ( qy - py ) * ( r x - px ) ; i f ( det > 0) return POSITIVE ; i f ( det < 0) return NEGATIVE ; return ZERO; p r q

12

13 Premiere guerre du Golfe - 100h plus tard 28 GI morts et 98 blesses iraquiensUS antimissile Patriot missile Scud Premiere guerre du Golfe - explication L'anti-missile Patriot est prevu pour fonctionner pendant quelques heures. Mais ca marchait tellement bien qu'ils l'ont laisse branche. L'horloge interne ajoute 0.1s a chaque tic. Mais 0.1 n'est pas exact en binaire : une petite erreur a chaque tic au bout de 100h, une erreur susante pour rater le missile

14 Mon banquier m'a propose cet investissement : vous me donnez e=2.71828... ¤, l'annee suivante, je prends 1¤ de frais et je multiplie par 1, l'annee suivante, je prends 1¤ de frais et je multiplie par 2, l'annee suivante, je prends 1¤ de frais et je multiplie par 3,... apres n ans, je prends 1¤ de frais et je multiplie par n, Pour recuperer mon argent, il y a 1¤ de frais. Dans 50 ans, pour ma retraite, combien d'argent aurai-je ?

15 Matlab C(format double) x = 2.7182818284590452354; for annee = 1 : 50 x = (x - 1) * annee; end x = -4.396803930182069e+048

16 MATLAB 1.718281828459045e+000 1.436563656918090e+000 1.309690970754271e+000 1.238763883017082e+000 1.193819415085411e+000 1.162916490512465e+000 1.140415433587258e+000 1.123323468698061e+000 1.109911218282548e+000 1.099112182825479e+000 1.090234011080270e+000 1.082808132963237e+000 1.076505728522079e+000 1.071080199309108e+000 1.066202989636622e+000 1.059247834185953e+000 1.007213181161205e+000 1.298372609016951e-001 -1.653309204286779e+001 -3.506618408573559e+002 -7.384898658004473e+003 Mathematica

17 #include main() { int n=1; double x=1.0, h=1.0, deriv=cos(x), diffquo,error; /* f(x)=sin(x) */ printf("deriv=%13.6e\n",deriv); printf("h diffquo abs(deriv-diffquo) \n"); while(n<=20){ h=h/10; diffquo=(sin(x+h)-sin(x))/h; error=fabs(deriv-diffquo); printf("%5.1e %13.6e %13.6e \n", h, diffquo, error); n++; } Approximating a derivative by a difference quotient

18 Error (absolute value of derivative minus difference quotient) as a function of h (Log-Log scale)

19 The truncation error of the finite difference approximation is bounded by Mh/2. Assuming the error in function values is bounded by ε, the rounding error is bounded by 2 ε/h. Total computational error is Where M is a bound on |f(t)| for t near x. There is a tradeoff between truncation error and rounding error in choosing the step size h. It is minimized when

20 x=ones(35,1); x(1)=11/2; x(2)=61/11; for i=3:35 x(i)=111-(1130-3000/x(i-2))/x(i-1); end x(35) Consider the recurrence In exact arithmetic the x k form a monotonically increasing sequence that converges to 6. Implement the recurrence and compare the computed x 34 with the true value 5.998 (to four correct signicant figures)

21 The mathematical convergence depends on the initial conditions x0, x1: convergence to 100 for almost all (x0, x1); convergence to 6 x0(11- x1)=30; convergence to 5 x0=x1=5 (exactly in machine representation) fplot('x^3-111*x^2+1130*x-3000',[-400,400])

22 fplot('x^3-111*x^2+1130*x-3000',[4,7]) fplot('x^3-111*x^2+1130*x-3000',[-10,110])

23 syms x1 x2 x3 x1=sym(11)/sym(2); x2=sym(61/11); for i=3:35 x3=111-(1130-3000/x1)/x2 x1=x2; x2=x3; end x3 x3=1721981182794095961389986301/287093876567205105910375321 5.99797252168491

24 Array[x,35]; x[1]=11/2; x[2]=61/11; Do[x[i+2]=111-(1130-3000/x[i])/x[i+1],{i,1,33}]; (*For[i=1,i<=33,i++,x[i+2]=111-(1130-3000/x[i])/x[i+1]];*) (*While[i<=33,x[i+2]=111-(1130-3000/x[i])/x[i+1];i++]; *) x[35]

25 Cancellation >>x=1.2e-8; (1-cos(x))/x^2 ans=0.7710 32 0.49999999999999999400001004443762 >>

26 Solving a Quadratic Equation If, Rename a, b, c so that abc (Kahan) The parentheses are essential!

27 Computing the Sample Variance (requires two passes through the data)

28 Accumulation of Rounding Errors Approximate by taking finite n in the definition e=exp(1) for i=1:15 n=10^i; (1+1/n)^n-e end

29 Instability Without Cancellation (1) The Need for Pivoting

30 (2) An Innocuous Calculation? for i=1:60 x=sqrt(x); end for i=1:60 x=x^2; end >>x=10; ans=1 >>x=0.5; ans=0

31 (3) An Infinite Sum Sum in the opposite order: from smallest to largest.

32 Rounding Errors Can Be Beneficial Power method Consider the matrix Which has eigenvalues 0, 0.4394, 1.161, and an eigenvector [1,1,1] T corresponding to the eigenvalue zero.

33 Gauss Givens Neumann Goldstine Turing Wilkinson Backward error analysis Condition number X (A nearby problem) Condition number, backward error

34 : :

35 References 1.C. W. Ueberhuber, Numerical Computation 1, Springer, 1997. 2.Sylvie Boldo, Pourquoi mon ordinateur calcule faux ? CR INRIA- Equipe-projet ProVal, 18 janvier, 2008. 3.M. T. Heath, Scientific Computing, An Introductory Survey, McGraw-Hill Companies, Inc., 2002. 4.M. L. Overton, Numerical Computing with IEEE Floating Point Arithmetic, SIAM, 2001. 5.N. Higham, Accuracy ans Stability of Numerical Algorithms, 2nd edition, SIAM, 2002.

36 1 For 2 While k 3 4 n=10^15 5 Matlab [X Y]=meshgrid(-6:0.5:6); Z=0.5*(3*X.^2 + 4*X.*Y+6*Y.^2)-2*X+8*Y; surf(X,Y,Z);


Télécharger ppt "Finite Precision Computation ( ). num=0; EPS=1; while (1+EPS)>1 EPS=EPS/2; num=num+1; end x=zeros(1,10); for n=1:10 x(n)=sin(n*pi/10); end EPS=1; for."

Présentations similaires


Annonces Google