fork download
  1. #include <cmath>
  2. #include <iostream>
  3. #include <clocale>
  4. using namespace std;
  5. double f(double x){
  6. double f;
  7. f = 2*cos(3*x)+3*pow(sin(x),2)-pow(x,2)+3*x;
  8. return f;
  9. }
  10. double f1(double x){
  11. double f1;
  12. f1 = 3-2*x+6*cos(x)*sin(x)-6*sin(3*x);
  13. return f1;
  14. }
  15. int main()
  16. {
  17. setlocale(LC_ALL,"Rus");
  18. double a, b, e, x;
  19. int k;
  20. a = 1;
  21. b = 4;
  22. e = 0.001;
  23. if(f(a)*f1(a)>0){
  24. cout<<"Условия сходства выполнены для x=a="<<a<<endl;
  25. x = a;
  26. }
  27. else{
  28. if(f(b)*f1(b)>0){
  29. cout<<"Условия сходства выполнены для x=b="<<b<<endl;
  30. x = b;
  31. }
  32. else{
  33. cout<<"Условия не выполнено";
  34. x=-10E10;
  35. }
  36. }
  37. if(x>-10E10){
  38. k=0;
  39. while(1){
  40. x=x-f(x)/f1(x);
  41. k=k+1;
  42. if(fabs(f(x))<e)break;
  43. }
  44. cout<<"Решения x="<<x<<endl;
  45. cout<<"Количество итераций k="<<k<<endl;
  46. }
  47. }
  48.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty