求解方程 語言:c

來源:互聯網
上載者:User
文章目錄
  • 求解方程
求解方程時限:1000ms 記憶體限制:10000K  總時限:3000ms

描述:

用牛頓迭代法求方程2x^3-4x^2+3xsinx-6=0的根,要求誤差小於10的-6次方。

輸入:

一個浮點數,表示起始點。

輸出:

一個浮點數,為方程的根。

輸入範例:

1.0

輸出範例:

2.064076

提示:

 

來源:

代碼:

  1. #include <stdio.h>
  2. #include <math.h>
  3. float fun1(float a);
  4. float fun2(float b);
  5. int main()
  6. {
  7. float x0,x1;
  8. float a,b;
  9. scanf("%f",&x0);
  10. while(1)
  11. {
  12. a=fun1(x0);
  13. b=fun2(x0);
  14. x1=x0-a/b;
  15. if(fabs(x1-x0)<=0.000001)
  16. break;
  17. else
  18. x0=x1;
  19. }
  20. printf("%.6f\n",x0);
  21. return 0;
  22. }
  23. float fun1(float a)
  24. {
  25. return 2*a*a*a-4*a*a+3*a*sin(a)-6;
  26. }
  27. float fun2(float b)
  28. {
  29. return 6*b*b-8*b+3*sin(b)+3*b*cos(b);
  30. }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.