Guest User

Untitled

a guest
May 20th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. close all;
  2. clc;
  3. clear;
  4.  
  5. F='1000./(x.^2-9*x+68)'
  6. func = inline(F);
  7. F='(-2000*x+9000)./((x.^2-9*x+68).^2)'
  8. DerivativeFunc=inline(F);
  9. F='(((2000.*(2*x-9).^2)./(x.^2-9*x+68))-2000)./((x.^2-9*x+68).^2)'
  10. Derivative2Func = inline(F);
  11.  
  12. simple =[];
  13. modSimple =[];
  14. RungeKutta =[];
  15. modRungeKutta =[];
  16. secondDerivativeOnePoint=[];
  17. secondDerivativeTwoPoints=[]
  18.  
  19. for i= 10:100
  20.  
  21. x = linspace(2, 4, i);
  22. [d, ind] = min(abs(x - 3));
  23. h=x(2)-x(1);
  24. k=rand * 0.001 - 0.0001;
  25.  
  26. f12 = func(x(ind - 2)) + k;
  27. f11 = func(x(ind - 1)) + k;
  28. f0 = func(x(ind)) + k;
  29. f1 = func(x(ind + 1)) + k;
  30. f2 = func(x(ind + 2)) + k;
  31. f3 = func(x(ind + 3)) + k;
  32.  
  33.  
  34.  
  35. p1 = (f1 - f0)/h;
  36. del1 = abs(DerivativeFunc(x(ind)) - p1);
  37. alpha1 = -log(del1)/log(ind);
  38. simple= [simple alpha1];
  39.  
  40.  
  41. p2 = (f1 - f11)/(2*h);
  42. del2 = abs(DerivativeFunc(x(ind)) - p2);
  43. alpha2 = -log(del2)/log(ind);
  44. modSimple= [modSimple alpha2];
  45.  
  46.  
  47. p3 = (-3 * f0 + 4 * f1 - f2)/(2*h);
  48. del3 = abs(DerivativeFunc(x(ind)) - p2);
  49. alpha3 = -log(del3)/log(ind);
  50. RungeKutta= [RungeKutta alpha3];
  51.  
  52.  
  53. p4 = (-11 * f0 + 18 * f1 - 9 * f2 + 2 * f3)/(6*h);
  54. del4 = abs(DerivativeFunc(x(ind)) - p4);
  55. alpha4 = -log(del4)/log(ind);
  56. modRungeKutta= [modRungeKutta alpha4];
  57.  
  58.  
  59. p5 = (f1 - 2 * f0 + f11)/(h^2);
  60. del5 = abs(Derivative2Func(x(ind)) - p5);
  61. alpha5 = -log(del5)/log(ind);
  62. secondDerivativeOnePoint= [secondDerivativeOnePoint alpha5];
  63.  
  64. p6 = (- f12 + 16 * f11 - 30 * f0 + 16 * f1 - f2)/(12 * h^2);
  65. del6 = abs(Derivative2Func(x(ind)) - p6);
  66. alpha6 = -log(del6)/log(ind);
  67. secondDerivativeTwoPoints = [secondDerivativeTwoPoints alpha6];
  68. end
  69.  
  70. i=10:100;
  71. plot (i, simple, 'c');
  72. hold on
  73. plot (i, modSimple, 'g');
  74. plot (i, RungeKutta, 'k');
  75. plot (i, modRungeKutta, 'm');
  76. plot (i, secondDerivativeOnePoint, 'r');
  77. plot (i, secondDerivativeTwoPoints, 'y');
  78. legend('Simpal', 'modSimple','RungeKutta', 'modRungeKutta', 'secondDerivativeOnePoint', 'secondDerivativeTwoPoints');
  79. grid on;
Add Comment
Please, Sign In to add comment