ejercicio informatica

35
LISTA DE EJERCICIOS 3 2.-Implemente en Matlab el algoritmo del método de bisección y póngalo aprueba resolviendo las siguientes ecuaciones: a) y=x^(-1)-tan(x) function y=f(x) y=x^(-1)-tan(x) >> %M,d,e:criterios de detencion a=input('a='); b=input('b='); M=input('M='); d=0.000000001; e=0.000000001; u=f(a); v=f(b); c=b-a; fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v); if sign(u)==sign(v); break; else for R=1:M E=c/2; c=a+E; w=f(c); fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E); if abs(E)<d || abs(w)<e break; end

Upload: cynthia-lizbeth-bautista-munoz

Post on 03-Feb-2016

224 views

Category:

Documents


0 download

DESCRIPTION

aplicacion de algoritmos

TRANSCRIPT

Page 1: ejercicio informatica

LISTA DE EJERCICIOS 3

2.-Implemente en Matlab el algoritmo del método de bisección y póngalo aprueba resolviendo las siguientes ecuaciones:

a) y=x^(-1)-tan(x)

function y=f(x) y=x^(-1)-tan(x)

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

Page 2: ejercicio informatica

else

a=c;

u=w;

end

c=b-a;

end

end

a=0

b=1.570796

M=23

0 1.570796 Inf -3060022.670333

1 0.785398 0.273240 0.785398

2 1.178097 -1.565385 0.392699

3 0.981748 -0.478013 0.196350

4 0.883573 -0.086734 0.098175

5 0.834485 0.095014 0.049087

6 0.859029 0.004827 0.024544

7 0.871301 -0.040749 0.012272

8 0.865165 -0.017914 0.006136

9 0.862097 -0.006532 0.003068

10 0.860563 -0.000850 0.001534

11 0.859796 0.001990 0.000767

12 0.860180 0.000570 0.000383

13 0.860371 -0.000140 0.000192

14 0.860275 0.000215 0.000096

15 0.860323 0.000038 0.000048

16 0.860347 -0.000051 0.000024

17 0.860335 -0.000006 0.000012

18 0.860329 0.000016 0.000006

19 0.860332 0.000005 0.000003

Page 3: ejercicio informatica

20 0.860334 -0.000001 0.000001

21 0.860333 0.000002 0.000001

22 0.860333 0.000000 0.000000

23 0.860334 -0.000000 0.000000

b) y=x^(-1)-2^x

function y=f(x) y=x^(-1)-2^x

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

Page 4: ejercicio informatica

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=0

b=1

M=23

0 1.000000 Inf -1.000000

1 0.500000 0.585786 0.500000

2 0.750000 -0.348459 0.250000

3 0.625000 0.057789 0.125000

4 0.687500 -0.155945 0.062500

5 0.656250 -0.052171 0.031250

6 0.640625 0.001971 0.015625

7 0.648438 -0.025301 0.007813

8 0.644531 -0.011716 0.003906

9 0.642578 -0.004885 0.001953

10 0.641602 -0.001460 0.000977

11 0.641113 0.000255 0.000488

12 0.641357 -0.000603 0.000244

13 0.641235 -0.000174 0.000122

14 0.641174 0.000040 0.000061

15 0.641205 -0.000067 0.000031

16 0.641190 -0.000013 0.000015

17 0.641182 0.000013 0.000008

Page 5: ejercicio informatica

18 0.641186 -0.000000 0.000004

19 0.641184 0.000007 0.000002

20 0.641185 0.000003 0.000001

21 0.641185 0.000002 0.000000

22 0.641186 0.000001 0.000000

23 0.641186 0.000000 0.000000

c) y=2^(-x)+exp(x)+2*cos(x)-6

function y=f(x) y=2^(-x)+exp(x)+2*cos(x)-6

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

Page 6: ejercicio informatica

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=1

b=3

M=23

1 3.000000 -1.701114 12.230552

1 2.000000 0.806762 1.000000

2 1.500000 -1.023283 0.500000

3 1.750000 -0.304588 0.250000

4 1.875000 0.194379 0.125000

5 1.812500 -0.068274 0.062500

6 1.843750 0.059637 0.031250

7 1.828125 -0.005157 0.015625

8 1.835938 0.027029 0.007813

9 1.832031 0.010883 0.003906

10 1.830078 0.002850 0.001953

11 1.829102 -0.001157 0.000977

12 1.829590 0.000846 0.000488

13 1.829346 -0.000155 0.000244

14 1.829468 0.000345 0.000122

15 1.829407 0.000095 0.000061

16 1.829376 -0.000030 0.000031

Page 7: ejercicio informatica

17 1.829391 0.000032 0.000015

18 1.829384 0.000001 0.000008

19 1.829380 -0.000015 0.000004

20 1.829382 -0.000007 0.000002

21 1.829383 -0.000003 0.000001

22 1.829383 -0.000001 0.000000

23 1.829384 0.000000 0.000000

d) y=(x^3+4*(x^2)+3*x+5)/(2*(x^3)-9*(x^2)+18*x-2)

function y=f(x)y=(x^3+4*(x^2)+3*x+5)/(2*(x^3)-9*(x^2)+18*x-2)

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

Page 8: ejercicio informatica

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=0

b=4

M=34

0 4.000000 -2.500000 2.685185

1 2.000000 2.500000 2.000000

2 1.000000 1.444444 1.000000

3 0.500000 1.525000 0.500000

4 0.250000 3.055556 0.250000

5 0.125000 48.017241 0.125000

6 0.062500 -5.720075 0.062500

7 0.093750 -13.635545 0.031250

8 0.109375 -39.452085 0.015625

9 0.117188 -491.532244 0.007813

10 0.121094 105.796323 0.003906

11 0.119141 268.603633 0.001953

12 0.118164 1179.545122 0.000977

13 0.117676 -1687.901607 0.000488

14 0.117920 7819.387622 0.000244

Page 9: ejercicio informatica

15 0.117798 -4306.132247 0.000122

16 0.117859 -19173.2306770.000061

17 0.117889 26406.787774 0.000031

18 0.117874 -140004.309037 0.000015

19 0.117882 65089.662847 0.000008

20 0.117878 243282.5677350.000004

21 0.117876 -659594.982411 0.000002

22 0.117877 770899.6344190.000001

23 0.117877 -9136822.864035 0.000000

24 0.117877 1683871.753217 0.000000

25 0.117877 4128628.877265 0.000000

26 0.117877 15064329.924186 0.000000

27 0.117877 -46441154.369637 0.000000

28 0.117877 44593731.746776 0.000000

29 0.117877 2242024345.462877 0.000000

30 0.117877 -94846963.165185 0.000000

31 0.117877 -198073248.829801 0.000000

32 0.117877 -434535882.151458 0.000000

3.-Encuentre una raíz de

x^8-36.001*x^7+546*x^6-4536*x^5+22449*x^4-67284*x^3+118124*x^2-109584*x+40320

function y=f2(x);y=x^8-36*x^7+546*x^6-4536*x^5+22449*x^4-67284*x^3+118124*x^2-109584*x+40320;

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f2(a);

v=f2(b);

Page 10: ejercicio informatica

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f2(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=5.5

b=6.5

M=34

5.500000e+00 6.500000 -55.371094 121.816406

1 6.000000 0.000000 0.500000

Page 11: ejercicio informatica

En el intervalo [5.5,6.5].cambie -36 por -36.001 y repita el ejercicio

function y=f2(x);y=x^8-36.001*x^7+546*x^6-4536*x^5+22449*x^4-67284*x^3+118124*x^2-109584*x+40320;>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f2(a);

v=f2(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f2(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

Page 12: ejercicio informatica

c=b-a;

end

end

a=5.5

b=6.5

M=34

5.500000e+00 6.500000 -207.614617 -368.406383

4.- Encuentre todos los ceros de:

a)1/x^3+sin(x)-exp(x)

La primera raíz se obtiene en el intervalo[-4,-2]

>> f=@(x)1/x^3+sin(x)-exp(x)

f =

@(x)1/x^3+sin(x)-exp(x)

Page 13: ejercicio informatica

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

Page 14: ejercicio informatica

end

end

a=-4

b=-2

M=23

-4 -2.000000 0.722862 -1.169633

1 -3.000000 -0.227944 1.000000

2 -3.500000 0.297262 0.500000

3 -3.250000 0.040290 0.250000

4 -3.125000 -0.093297 0.125000

5 -3.187500 -0.026262 0.062500

6 -3.218750 0.007088 0.031250

7 -3.203125 -0.009570 0.015625

8 -3.210938 -0.001236 0.007813

9 -3.214844 0.002927 0.003906

10 -3.212891 0.000846 0.001953

11 -3.211914 -0.000195 0.000977

12 -3.212402 0.000325 0.000488

13 -3.212158 0.000065 0.000244

14 -3.212036 -0.000065 0.000122

15 -3.212097 -0.000000 0.000061

16 -3.212128 0.000033 0.000031

17 -3.212112 0.000016 0.000015

18 -3.212105 0.000008 0.000008

19 -3.212101 0.000004 0.000004

20 -3.212099 0.000002 0.000002

21 -3.212098 0.000001 0.000001

22 -3.212098 0.000000 0.000000

23 -3.212097 0.000000 0.000000

Page 15: ejercicio informatica

La segunda raíz se obtiene en el intervalo[0,2]

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

Page 16: ejercicio informatica

end

end

a=0

b=2

M=23

0 2.000000 Inf -6.354759

1 1.000000 -0.876811 1.000000

2 0.500000 6.830704 0.500000

3 0.750000 0.935009 0.250000

4 0.875000 -0.138620 0.125000

5 0.812500 0.336834 0.062500

6 0.843750 0.086858 0.031250

7 0.859375 -0.028628 0.015625

8 0.851563 0.028391 0.007813

9 0.855469 -0.000295 0.003906

10 0.853516 0.014004 0.001953

11 0.854492 0.006844 0.000977

12 0.854980 0.003272 0.000488

13 0.855225 0.001488 0.000244

14 0.855347 0.000597 0.000122

15 0.855408 0.000151 0.000061

16 0.855438 -0.000072 0.000031

17 0.855423 0.000040 0.000015

18 0.855431 -0.000016 0.000008

19 0.855427 0.000012 0.000004

20 0.855429 -0.000002 0.000002

21 0.855428 0.000005 0.000001

22 0.855428 0.000001 0.000000

23 0.855428 -0.000000 0.000000

Page 17: ejercicio informatica

b)x^3-tan(x)-exp(x)

Esta función cuenta con seis raíces

La primera raíz se encuentra en el intervalo[-2,-1]

>> f=@(x)x^3-tan(x)-exp(x)

f =

@(x)x^3-tan(x)-exp(x)

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

Page 18: ejercicio informatica

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=-2

b=-1

M=23

-2 -1.000000 -10.320375 0.189528

1 -1.500000 10.503290 0.500000

Page 19: ejercicio informatica

2 -1.750000 -11.053529 0.250000

3 -1.625000 -22.918790 0.125000

4 -1.562500 116.508197 0.062500

5 -1.593750 -47.809710 0.031250

6 -1.578125 -140.584552 0.015625

7 -1.570313 2062.775005 0.007813

8 -1.574219 -296.297834 0.003906

9 -1.572266 -684.690789 0.001953

10 -1.571289 -2033.572609 0.000977

11 -1.570801 -224498.433013 0.000488

12 -1.570557 4168.040220 0.000244

13 -1.570679 8498.172044 0.000122

14 -1.570740 17669.787492 0.000061

15 -1.570770 38364.303878 0.000031

16 -1.570786 92551.367193 0.000015

17 -1.570793 314962.5551610.000008

18 -1.570797 -1563095.523873 0.000004

19 -1.570795 788894.0401710.000002

20 -1.570796 3185556.624393 0.000001

21 -1.570796 -6137960.313322 0.000000

22 -1.570796 13245397.523199 0.000000

23 -1.570796 -22877336.512521 0.000000

La segunda raíz se encuentra en el intervalo[-1,0]

%M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

Page 20: ejercicio informatica

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=-1

b=0

M=23

-1 0.000000 0.189528 -1.000000

1 -0.500000 -0.185228 0.500000

2 -0.750000 0.037355 0.250000

Page 21: ejercicio informatica

3 -0.625000 -0.057918 0.125000

4 -0.687500 -0.006641 0.062500

5 -0.718750 0.016190 0.031250

6 -0.703125 0.004994 0.015625

7 -0.695313 -0.000767 0.007813

8 -0.699219 0.002127 0.003906

9 -0.697266 0.000684 0.001953

10 -0.696289 -0.000041 0.000977

11 -0.696777 0.000322 0.000488

12 -0.696533 0.000140 0.000244

13 -0.696411 0.000050 0.000122

14 -0.696350 0.000004 0.000061

15 -0.696320 -0.000018 0.000031

16 -0.696335 -0.000007 0.000015

17 -0.696342 -0.000001 0.000008

18 -0.696346 0.000002 0.000004

19 -0.696344 0.000000 0.000002

20 -0.696343 -0.000000 0.000001

21 -0.696344 -0.000000 0.000000

22 -0.696344 0.000000 0.000000

23 -0.696344 -0.000000 0.000000

La tercera raíz se encuentra en el intervalo[1,2]

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

Page 22: ejercicio informatica

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=1

b=2

M=23

1 2.000000 -3.275690 2.795984

1 1.500000 -15.208109 0.500000

2 1.750000 5.125152 0.250000

3 1.625000 17.643459 0.125000

Page 23: ejercicio informatica

4 1.562500 -121.488542 0.062500

5 1.593750 42.684375 0.031250

6 1.578125 135.532329 0.015625

7 1.570313 -2067.791136 0.007813

8 1.574219 291.263696 0.003906

9 1.572266 679.665664 0.001953

10 1.571289 2028.551984 0.000977

11 1.570801 224493.4146350.000488

12 1.570557 -4173.057474 0.000244

13 1.570679 -8503.189860 0.000122

14 1.570740 -17674.8055880.000061

15 1.570770 -38369.3221150.000031

16 1.570786 -92556.3855010.000015

17 1.570793 -314967.573503 0.000008

18 1.570797 1563090.505513 0.000004

19 1.570795 -788899.058522 0.000002

20 1.570796 -3185561.642749 0.000001

21 1.570796 6137955.294964 0.000000

22 1.570796 -13245402.541556 0.000000

23 1.570796 22877331.494164 0.000000

La cuarta raíz se encuentra en el intervalo[4,4.5]

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

Page 24: ejercicio informatica

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=4

b=4.5

M=23

4 4.500000 8.244029 -3.529463

1 4.250000 4.653904 0.250000

2 4.375000 1.449783 0.125000

3 4.437500 -0.728391 0.062500

4 4.406250 0.422185 0.031250

Page 25: ejercicio informatica

5 4.421875 -0.136198 0.015625

6 4.414063 0.147005 0.007813

7 4.417969 0.006432 0.003906

8 4.419922 -0.064623 0.001953

9 4.418945 -0.029031 0.000977

10 4.418457 -0.011284 0.000488

11 4.418213 -0.002422 0.000244

12 4.418091 0.002006 0.000122

13 4.418152 -0.000208 0.000061

14 4.418121 0.000899 0.000031

15 4.418137 0.000346 0.000015

16 4.418144 0.000069 0.000008

17 4.418148 -0.000069 0.000004

18 4.418146 -0.000000 0.000002

19 4.418145 0.000034 0.000001

20 4.418146 0.000017 0.000000

21 4.418146 0.000008 0.000000

22 4.418146 0.000004 0.000000

23 4.418146 0.000002 0.000000

La quinta raíz se encuentra en el intervalo[4.6,4.7]

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

Page 26: ejercicio informatica

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

end

a=4.6

b=4.7

M=23

4.600000e+00 4.700000 -11.008491 -86.836935

Page 27: ejercicio informatica

La sexta raíz se encuentra en el intervalo[4.7,4.9]

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

Page 28: ejercicio informatica

end

end

a=4.7

b=4.9

M=23

4.700000e+00 4.900000 -86.836935 -11.373287

c)x-tanh(x)-exp(-1/x)

La raíz se encuentra en el intervalo [0,1]

>> f=@(x)x-tanh(x)-exp(-1/x)

f =

@(x)x-tanh(x)-exp(-1/x)

Page 29: ejercicio informatica

>> %M,d,e:criterios de detencion

a=input('a=');

b=input('b=');

M=input('M=');

d=0.000000001;

e=0.000000001;

u=f(a);

v=f(b);

c=b-a;

fprintf ('%d\t%f\t%f\t%f\n',a,b,u,v);

if sign(u)==sign(v);

break;

else

for R=1:M

E=c/2;

c=a+E;

w=f(c);

fprintf ('%d\t%f\t%f\t%f\n',R,c,w,E);

if abs(E)<d || abs(w)<e

break;

end

if sign(w)~=sign(u)

b=c;

v=w;

else

a=c;

u=w;

end

c=b-a;

end

Page 30: ejercicio informatica

end

a=0

b=1

M=23

0 1.000000 0.000000 -0.129474

1 0.500000 -0.097452 0.500000

2 0.250000 -0.013234 0.250000

3 0.125000 0.000312 0.125000

4 0.062500 0.000081 0.062500

5 0.031250 0.000010 0.031250

6 0.015625 0.000001 0.015625

7 0.007813 0.000000 0.007813

8 0.003906 0.000000 0.003906

9 0.001953 0.000000 0.001953

10 0.000977 0.000000 0.000977

Page 31: ejercicio informatica

d)x^3+sin(x)-exp(-1/x^2)

La raíz esta en el intervalo[-2,2]

5.-Nota 1: Definir una función matemática y=f(x) en Matlab puede hacerse como una función normal en Matlab .También puede crear una referencia a función usando. por ejemplo , la sintaxis:

f=@ (x) x-tan(x)

para referirse a la función y=x-tanx.

6.Nota2: le convendrá guardar sus resultados pues después deberá entregar un informe de prácticas de laboratorio .La expresión ‘diary nombre’ escrita al iniciar la sesión la guarda en un archivo con un formato simple que después puede editarse un proceso de texto . Las figuras pueden guardarse en algun formato conveniente como .bmp,.emf,.pdf,etc . al terminar al sesión escriba ‘diary off’.