Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
數值分析作業 Secant-Method

數值分析作業 Secant-Method

Ratings:

4.67

(3)
|Views: 902 |Likes:
Published by ChiChiChen
我的報告
我的報告

More info:

Published by: ChiChiChen on Jun 14, 2007
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as ODT, PDF, TXT or read online from Scribd
See more
See less

05/08/2014

pdf

text

original

 
數值分析第二次作業Secant Method
課本113頁,問題(3.7)(c)組別: 第六組學生: 陳器奇、謝鎮宇學號:9301062a、9301035a程式碼(使用C++語言):#include <stdio.h>#include <math.h> double f(double x)//(1){return (-x*x*x)+x+1;} double SecantMethod(double xn_1, double xn, double e, int m)//(2){int n;double d;for (n = 1; n <= m; n++)//(3){d = (xn - xn_1) / (f(xn) - f(xn_1)) * f(xn);//(4)if (fabs(d) < e)return xn;xn_1 = xn;xn = xn - d;printf("\n %15.15f, %15.15f ", xn,f(xn));}return xn;}int main(void)//(5){double xm_1,xm,E;int M;printf("\n Enter 1st initial guess x0:");//(6)scanf("%lf", &xm_1);printf(" Enter 2nd initial guess x1:");scanf("%lf", &xm);printf(" Enter Max iteration number:");//(7)scanf("%d", &M);printf(" Enter tolerance:");//(8)scanf("%lf", &E);
 
printf("\n\n %15.15f \n", SecantMethod(xm_1, xm, E, M));//(9)return 0;}程式說明:欲解方程式:
3
+ x + 1 = 0Secant Method解法方程式如下圖(圖1)所式(1)Secant Method持續執行直到以下兩個條件其中之一發生:1.|
+ 1
 
| <
 2.
>
 說明(1):宣告副程式函式f型別為雙精度浮點數,傳入值x,回傳(-x*x*x)+x+1計算後值。說明(2):宣告副程式函式SecantMethod型別為雙精度浮點數,傳入值xn_1, xn, e, m說明(3):使用For迴圈疊代m說明(4):Secant Method右式(1)assignd,如d的絕對值小於e(Tolerance,最小忍值),回傳xn的值。把xn assignxn_1,再把(xn-d) assignxn(疊代置xnxn_1的值)。螢幕輸xnf(xn)的值。說明(5):主程式,宣xm_1,xm,E,M的型別說明(6):輸入第一個和第二個起始猜測值x0x1。說明(7):輸入最大疊代數目。說明(8):輸入最小容忍值。說明(9):螢幕顯示SecantMethod回傳值(SecantMethod函式傳入值xm_1, xm, E, M計算後之值)。程式執行結果及討論:[
況一
:改x0,x1的相隔區間,固定最大疊代數為50及最小容忍值0.00001 ](1)x01.1x11.2
Enter 1st initial guess x0:1.1
 
Enter 2nd initial guess x1:1.2Enter Max iteration number:50Enter tolerance:0.000011.358922558922559, -0.1505596711636001.320488768042503, 0.0179649335929401.324585858208551, 0.0005632845615641.324718479412076, -0.0000022268531101.324718479412076
xn1.3247184794120764f(x)-0.000002226853110(2)x01.1x150
Enter 1st initial guess x0:1.1Enter 2nd initial guess x1:50Enter Max iteration number:50Enter tolerance:0.000011.100300953737658, 0.7682081927512981.100601595747396, 0.7674166086390561.392064837568101, -0.3055403682523731.309066368705039, 0.0657785578618401.323769415607835, 0.0040416071485031.324731950018435, -0.0000596748225521.324717944868202, 0.0000000527814161.324717944868202
xn1.3247179448682027f(x)0.000000052781416(3)x01.001x11.002 
Enter 1st initial guess x0:1.001Enter 2nd initial guess x1:1.002Enter Max iteration number:50Enter tolerance:0.000011.497761334828597, -0.8621502163429661.267734989017586, 0.2302921629315231.316225660665854, 0.0359305282770301.325189854921204, -0.0020133555022001.324714202246012, 0.0000160136354771.324714202246012
xn1.3247142022460125f(x)0.000016013635477
結論一
:從實驗(1)(2)(3),可得出一個可能趨勢,當固定最大疊代數及最小容忍值,起始猜測值x0x1的相隔區間越大時,f(x)的值越趨近零,也就是說xn(解)精確度越高。[
況二
:改變最小容忍值,固定最大疊代數為50x0,x1的值各別1.1,1.2 ]

Activity (2)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->