NA Done 1

Share Embed Donate


Short Description

numerical analysis...

Description

Numerical Analysis Laboratory Work Nr. 1 Chele Natalia [FAF-131]

Problem 1: Implement the function

Try to evaluate this function for x=10, 100, 1000. Please explain the result. Find a way to increase accuracy of the evaluation. Code in Matlab: >> x=10; >> y=(x.*exp(x)-1./(x.^2))./(x.*exp(x)+1./(x.^2)) y = 1.0000 >> x=100; >> y=(x.*exp(x)-1./(x.^2))./(x.*exp(x)+1./(x.^2)) y = 1 >> x=1000; >> y=(x.*exp(x)-1./(x.^2))./(x.*exp(x)+1./(x.^2)) y = NaN Comments: For obtaining corresponding results I divided the fraction to exp(x) because 1/exp(x) is very close to 0, then we have more accuracy in the result. >> x=1000; >> y=(x-(1/(x.^2.*exp(x))))/(x+(1/(x.^2.*exp(x)))) y = 1 Evrica!!! I got the same result as in previous cases.

Problem 2: Implement the following procedure

Please explain obtained results. Results: >> c=0.1; >> for x=1:15 r=10^(1+(2.*x./10))-10^(1+2.*x.*c) display r end r r r r r r r r r r r r r r r

= 0 = 0 = 0 = 0 = 0 = 0 =-2.5580e-013 = 0 = 0 = 0 = 0 =-2.2737e-012 = 0 = -6.3665e-012 = 0

Comments: Here the problem is in the value c=0.1 (1/10) because it hasn’t be stored in finite binary. It is infinite number of 0 and 1,then in floating point arithmetic the results are with errors.

Problem 3: Compute the integral that

Using integration by parts show

Using your favorite programming system compute Ik for k=0,1,2,3,: : :,25. Do you notice anything wrong with your answers? To analyze this suppose that the only error is in . Then if all calculations are exact, what is the error in ? What error do you expect if _ = u, where u is the unit of roundoff?

1

1

I o=∫ e−x x0 =∫ e−x =−e−1+ e0 =1−e−1 0

0

|

1

I k =∫ e−k x k = 0

|

u=x k du=k x k−1 = ¿−1k ∙ e−1 +0k e−0 +k ∫ x k−1 ∙ e x =k ∫ e−x x k−1 dx−e−1=k ∙ I k−1−e−1 −x −x dv=e v=−e dx

The result of computing the integral in Matlab function lab() I0 = 1 - exp(-1) for i = 1:25 Ik = -exp(-1)+i*I0; disp(Ik); I0 = Ik; end end

nr

Result of iterations

0

0.6321

1

0.2642

2

0.1606

3

0.1139

4

0.0878

5

0.0713

6

0.0599

7

0.0517

8

0.0454

9

0.0404

10

0.0365

11

0.0332

12

0.0305

13

0.0281

14

0.0262

15

0.0244

16

0.0222

17

0.0096

18

-0.1959

19

-4.0905

20

-82.1769

21

-1.73E+03

22

-3.80E+04

23

-8.73E+05

24

-2.10E+07

25

-5.24E+08

Comments: The error occur when exp(-1) is computed. At the first iteration the error is small, but taking into account the fact that the next values are computed using the previous result the error is propagated further and its value is increasing with each iteration . That’s why I obtained the negative values . Problem 4. MATLAB source Code : function [M]=JuliaSet(zMax, c, N, x) space = linspace(-zMax, zMax, x); [real, imag] = meshgrid(space, space); Z = real+i*imag; for j=1:x for k=1:x M(j, k) = EscVel(Z(j, k), c, N); end end end function [n] = EscVel (z0, c, N) n=1; zu=z0; zn=zu^2+c; while ((abs(zn) M = JuliaSet(1.5, 0.3141592+i*0.161803399, 100, 1000); >> imagesc(atan(0.1*M)

100 200 300 400 500 600 700 800 900 1000

Finally Done !

100

200

300

400

500

600

900

1000

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF