2009-11-18 16:59:51| 分類: 計算方法數學類 |字型大小 訂閱
//牛頓迭代法,牛頓下山迭代
#include #include float newtonfun(float x0,float c);
float xiashanfun(float x0,float c);
float fun1(float x,float p);//下山迭代函式
float fun2(float x);//原函式f(x)
void main()
else
x=newtonfun(y,1e-4);
printf("牛頓迭代結果是:%f\n",x);
}float newtonfun(float x0,float c)
printf("共經過%d次迭代\n",n);
return i;
}float xiashanfun(float x0,float c)
printf("%-12f%-12f%f\n",a,q,fun2(a));
} return a;
}float fun1(float x,float p)
float fun2(float x)
/*在本例題中,方程解在1.5左右,輸入0.6讓其牛頓下山*/
牛頓下山法
因牛頓迭代法受初值選取的限制,為防止迭代發散,對迭代過程再附加一項要求 f x k 1 f x k 將牛頓法迭代的結果 x k 1 x k f x k f x k 和前一近似值x k 適當加權平均做為新的改進值 x k 1 lambda x k 1 1 lambda x k 其中0 lambda 1...
牛頓下山法
輸入 初值,誤差限,迭代最大次數,下山最大次數 輸出 近似根各步下山因子 定義佇列儲存近似根 queue root 記錄每步的下山次數 queue count 記錄每步的因子 queue factor 定義原函式 double function double x,double y 定義導函式 dou...
MATLAB之牛頓下山法
其中引數 它改進了牛頓法對初值的依賴性,當所選初值不合適時 不滿足單調性 f x k 1 下山因子 可用逐步搜尋法確定,即先令下山因子 1,判斷單 調性是否成立,若不成立將縮小1 2,直到單調性滿足為止。其他步驟與牛頓法相同,牛頓下山法為牛頓法的改進。bash clcclear syms x h x...