Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using System;
  2.  
  3. namespace KR
  4. {
  5. class Program
  6. {
  7. public static double f(double x){
  8. return 2*x*x-8*x-7;
  9. }
  10. public static void Main(string[] args)
  11. {
  12. Console.WriteLine("Исходный пример - f(x)=2*x*x - 8*x -7 | X=[0;3] \n Точность = 0.5");
  13. double a=0;
  14. double b=3;
  15. double E=0.5;
  16. double sh=(b-a)/4;
  17. double x0=a;
  18. double Fx0=f(x0);
  19. double x,F;
  20. M: double x1=x0+sh;
  21. double Fx1=f(x1);
  22. if(Fx0>Fx1){
  23. x0=x1;
  24. Fx0=Fx1;
  25. if(x0>a&&x0<b){
  26. goto M;
  27. }
  28. }
  29. if(Math.Abs(sh)>E){
  30. x=x0;
  31. F=f(x0);
  32. }
  33. else{
  34. x0=x1;
  35. Fx0=Fx1;
  36. sh=-sh/4;
  37. goto M;
  38. }
  39. Console.WriteLine("Найденное X = {0}, Значение функции = {1}",x,F);
  40. Console.ReadKey(true);
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement