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.

Then if all calculations are exact. Results: >> c=0.*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.1.1 (1/10) because it hasn’t be stored in finite binary.Problem 2: Implement the following procedure Please explain obtained results. Do you notice anything wrong with your answers? To analyze this suppose that the only error is in .1.5580e-013 = 0 = 0 = 0 = 0 =-2. Problem 3: Compute the integral that Using integration by parts show Using your favorite programming system compute Ik for k=0.*x.3. where u is the unit of roundoff? .then in floating point arithmetic the results are with errors.25. It is infinite number of 0 and 1. what is the error in ? What error do you expect if _ = u. >> for x=1:15 r=10^(1+(2.2737e-012 = 0 = -6./10))-10^(1+2.*x.3665e-012 = 0 Comments: Here the problem is in the value c=0.2.: : :.

0305 13 0.0244 16 0.0454 9 0.0332 12 0.0878 5 0.0281 14 0.0365 11 0.exp(-1) for i = 1:25 Ik = -exp(-1)+i*I0. end end nr Result of iterations 0 0. I0 = Ik.1139 4 0.0096 .0599 7 0.2642 2 0. disp(Ik).0222 17 0.6321 1 0.1606 3 0.0262 15 0.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 .0713 6 0.0517 8 0.0404 10 0.

297491+i*0. space). x) space = linspace(-zMax. That’s why I obtained the negative values . zn=zu^2+c. N). zn=zu^2+c.1769 21 -1. N. c. end end M = JuliaSet(1. zu=z0. c.73E+03 22 -3. . MATLAB source Code : function [M]=JuliaSet(zMax.80E+04 23 -8. 100. k). 1000).1959 19 -4. k) = EscVel(Z(j.10E+07 25 -5. imag] = meshgrid(space. At the first iteration the error is small.0905 20 -82. end end end function [n] = EscVel (z0. 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 . while ((abs(zn)<2)&&(n<=N)) n=n+1. Problem 4. x).18 -0. -0. [real. Z = real+i*imag.73E+05 24 -2.24E+08 Comments: The error occur when exp(-1) is computed.641051. N) n=1. zMax. zu=zn. c. for j=1:x for k=1:x M(j.

>> imagesc(atan(0. 0.5.100 200 300 400 500 600 700 800 900 1000 100 200 300 400 500 600 700 800 700 800 900 1000 >> M = JuliaSet(1.161803399.3141592+i*0. 1000).1*M) 100 200 300 400 500 600 700 800 900 1000 Finally Done ! 100 200 300 400 500 600 900 1000 . 100.