Processing math: 14%

2013年5月2日 星期四

2.1 the besection method 習題組 2.1 NO.3

Numerical Analysis數值分析筆記 /  

2.1 The Bisection Method /  

習題組 2.1 /


NO. 3.
use the Bisection method to find solutions accurate to within 10^{-2} for x^{3}-7x^{2}+14x-6=0 on each interval.
  • 第01題 \left[0,\ 1\right].
  • 第02題 \left[1,\ 3.2\right].
  • 第03題 \left[3.2,\ 44\right].

2.1 NO.03c_01

C語言程式:

  1. #include <stdio.h>
  2. /*前置處理指命,就是把stdio.h這個檔案(此檔案附於安裝編譯器的子資料夾下)的內容放在原始程式的最開頭*/
  3. #include <stdlib.h>
  4. /*為了避免結果一閃而過(在windowXP系統下會出現此情形,均需加上此程式)*/
  5. #include <math.h>       /**/
  6. float f(float x);
  7. int main(void)
  8.     int i=0,N=100;
  9.     float a=3.2,b=4,p=0.0,FA=0.0,FP=0.0;
  10.     float TOL=0.00001;
  11.     printf("n      an              bn              pn              f(pn)\n");
  12.     /*Step1*/
  13.     i=1;
  14.     FA=f(a);
  15.     /*Step2*/
  16.     while(i<=N)
  17.     {    /*Step3*/
  18.          p=a+(b-a)/2;
  19.          FP=f(p);
  20.     printf("%2d    %+.9f    %+.9f    %+.9f    %+.9f\n",i,a,b,p,f(p));    
  21.          /*Step4*/
  22.          if(FP==0 || (b-a)/2<TOL)
  23.          {printf("n=%d, p=%+f\n",i,p);break;}
  24.          /*Step5*/
  25.          i=i+1;
  26.          /*Step6*/
  27.          if(FA*FP>0){a=p;FA=FP;}
  28.          else b=p;
  29.          }
  30.     printf("method failed after N=%d iterations.",N);
  31.     /*Step*/
  32.     /*Step*/
  33.     /*Step*/
  34. system("PAUSE"); /*為了避免結果一閃而過(在windowXP系統下會出現此情形,均需加上此程式)*/
  35. return 0;       
  36.    }
  37. float f(float x)
  38. {
  39.       return pow(x,3)-7*pow(x,2)+14*x-6;
  40.       }

C語言程式執行:

2.1  BisectionNO.3c



沒有留言:

張貼留言

下08第02章-一次函數

關於「一次函數」的四階層次學習單主題,預計用於四節課(每節45分鐘) 以下是針對「 一次函數 」主題設計的 四階層次學習單主題架構 ,預計使用四節課(每節 45 分鐘),每一階段包含清楚的學習目標、教學重點、活動練習與延伸挑戰,適合階段式推進學生對一次函數的理解與應用。 🎯 主...