Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. EPS=input('EPS=');
  2. gr=1;
  3. while(gr==1)
  4. xi=input('xi=');
  5. xf=input('xf=');
  6. if(xi>=xf)
  7. fprintf('xi>xf. Reintroduceti valorile');
  8. xi=input('xi=');
  9. xf=input('xf=');
  10. end
  11.  
  12. he=input('he=');
  13. if((he<=0) || (xi+he>=xf))
  14. fprintf('Reintroduceti pasul de evaluare he');
  15. he=input('he=');
  16. end
  17.  
  18. xe=xi:he:xf;
  19. np=length(xe);
  20. if(xe(np)<xf)
  21. xe=[xe xf];
  22. np=np+1;
  23. end
  24. ye=FCE(xe);
  25.  
  26. plot(xe,ye,'-r')
  27. grid
  28.  
  29. gr=input('Reluare vizualizare si inspectie grafica?DA=1.NU=0');
  30. end
  31.  
  32.  
  33.  
  34. %Metoda Muller
  35.  
  36.  
  37. mur=1;
  38. while(mur==1)
  39. x0=input('x0=');
  40. x1=input('x1=');
  41. x2=input('x2=');
  42.  
  43. f0=FCE(x0);
  44. f1=FCE(x1);
  45. f2=FCE(x2);
  46.  
  47. iter=0;
  48. xr=x2;
  49. fr=f2;
  50.  
  51. %Aplicare metoda Muller
  52.  
  53. while(abs(fr)>EPS)
  54. iter=iter+1;
  55. if(x2>x0)
  56. t=x2;
  57. x2=x0;
  58. x0=t;
  59. t=f2;
  60. f2=f0;
  61. f0=t;
  62. end
  63.  
  64. if(x0>x1)
  65. t=x0;
  66. x0=x1;
  67. x1=t;
  68. t=f0;
  69. f0=f1;
  70. f1=t;
  71. end
  72.  
  73. if(x2>x1)
  74. t=x2;
  75. x2=x1;
  76. x1=t;
  77. t=f2;
  78. f2=f1;
  79. f1=t;
  80. end
  81.  
  82. h1=x1-x0;
  83.  
  84. if(abs(h1)<EPS)
  85. fprintf('h1-nul:algoritmul nu converge');
  86. return
  87. end
  88.  
  89. h2=x0-x2;
  90. r=h2/h1;
  91. d=r*(r+1)*(h1^2);
  92.  
  93. if(abs(d)<EPS)
  94. fprintf('numitor nul pentru a');
  95. return
  96. end
  97.  
  98. a=(r*f1-f0*(1+r)+f2)/d;
  99. b=(f1-f0-a*(h1^2))/h1;
  100. c=f0;
  101. delta=b^2-4*a*c;
  102.  
  103. if(delta<=0)
  104. fprintf('radacini complexe sau confundate');
  105. return
  106. end
  107.  
  108.  
  109.  
  110. if(b>=0)
  111. d=b+sqrt(delta);
  112. else
  113. d=b-sqrt(delta);
  114. end
  115.  
  116.  
  117. if(abs(d)<EPS)
  118. fprintf('numitorul nul pt xr');
  119. return
  120. end
  121.  
  122. xr=x0-(2*c)/d;
  123. fr=FCE(xr);
  124.  
  125. if(xr<x0)
  126. x1=xr;
  127. f1=fr;
  128. else
  129. x2=xr;
  130. f2=fr;
  131. end
  132. end
  133. mur=input('Doriti introducerea altor estimatii DA=1.NU=0');
  134.  
  135. end
  136.  
  137. iter
  138. xr
  139. fr
  140.  
  141. function f=FCE(xe)
  142. f=sin(xe)-xe/2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement