2013年4月26日 星期五

2.1 the besection method 習題組 2.1 NO.5

Numerical Analysis數值分析筆記 / 2.1 The Bisection Method / 習題組 2.1 /

2.1 NO.05a_01
2.1 NO.05b_01

2013年4月25日 星期四

2.1 the besection method 習題組 2.1 NO.4

Numerical Analysis數值分析筆記 /  

2.1 The Bisection Method

習題組 2.1 /


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

>>第01題<< | 第02題 | 第03題 | 第04題

2.1 NO.04a_01
2.1 NO.04a_02
2.1 NO.04a_03
2.1 NO.04a_04


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=-2,b=-1,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,4)-2*pow(x,3)-4*pow(x,2)+4*x+4;
  40.       }

C 語言程式執行結果: 


2.1  BisectionNO.4a


>>第01題<< | 第02題 | 第03題 | 第04題




2013年4月24日 星期三

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.03a_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=0,b=1,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.3a 

2013年4月11日 星期四

2.1 the besection method 習題組 2.1 NO.2

Numerical Analysis數值分析筆記 / 2.1 The Bisection Method / 習題組 2.1 /



NO.2.
$f(x)=3(x+1)(x-\frac{1}{2})(x-1)$. Use the Bisection method on the following intervals to find $p_{3}$.
  • $\left[-2,\ 1.5\right]$
2.1 NO.02_012.1 NO.02_02

執行結果:

2.1  BisectionNO.2a 
  • $\left[-1.25,\ 2.5\right]$

2.1 NO.02_03

執行結果:
2.1  BisectionNO.2b

好像有算錯了^__^

2.1 the besection method 習題組 2.1 NO.1

Numerical Analysis數值分析筆記

2.1 The Bisection Method /

習題組 2.1 /



NO.1.
use the bisetion method to find the $p_3$ for $f(x)=\sqrt{x}-\cos x $ on $[0,1]$.


2.1 NO.01


C 式語言:

    1. #include <stdio.h>
    2. #include <stdlib.h>
    3. #include <math.h>       /**/
    4. float f(float x);
    5. int sig(float v);
    6. int main(void)
    7.     int i=0,N=100;
    8.     float a=0.0,b=1.0,p=(a+b)/2,FA=0.0,FP=0.0;
    9.     float TOL=0.00001;
    10.    
    11.     printf("n  an         bn         pn         f(pn)\n");
    12.     /*Step1*/
    13.     i=1;
    14.     FA=f(a);
    15.    
    16.     /*Step2*/
    17.     while(i<=N)
    18.     {    /*Step3*/
    19.          p=a+(b-a)/2;
    20.          FP=f(p);
    21.         
    22.     printf("%2d  %.9f  %.9f  %.9f  %+.9f\n",i,a,b,p,f(p));    
    23.         
    24.          /*Step4*/
    25.          if(FP==0 || (b-a)/2<TOL)
    26.          {printf("n=%d, p=%+f\n",i,p);break;}
    27.         
    28.          /*Step5*/
    29.          i=i+1;
    30.         
    31.          /*Step6*/
    32.          if(sig(FA)*sig(FP)>0){a=p;FA=FP;}
    33.          else b=p;
    34.          }
    35.     printf("method failed after N=%d iterations.",N);
    36.    
    37.    
    38.    
    39. system("PAUSE");
    40. return 0;       
    41.    }
    42.   
    43.   
    44. float f(float x)
    45. {
    46.       return sqrt(x)-cos(x);
    47.       }
    48.      
    49. int sig(float u)
    50. {   
    51.      if(u>0){return 1;}
    52.      else if(u<0){return -1;}
    53.      else {return 0;}
    54.      }

    c語言執行結果:

     2.1  BisectionNO.1
    教學用,若不慎侵犯絕非故意,請留言通知必於第一時間移除,謝謝。