資源簡(jiǎn)介
計(jì)算方法實(shí)驗(yàn)7--牛頓下山法.cpp
計(jì)算方法實(shí)驗(yàn)7--牛頓下山法.cpp
代碼片段和文件信息
#include?“stdio.h“
#include?“conio.h“
#include?“math.h“
#include?“stdlib.h“
#define?Et?1e-3??/*?下山因子下界?*/
#define?E1?1e-3??/*?根的誤差限?*/
#define?E2?1e-3???/*?殘量精度?*/
double?f(double?x)?{?return?x*x*x?-?x?-?1;}???/*?f(x)的表達(dá)式?*/
double?f1(double?x)?{?return?3*x*x?-?1;}??/*?f(x)的導(dǎo)數(shù)?*/
void?main()
{
????int?b;
????
????double?f(double);
????double?f1(double);
????
????void?errormess(int);???/*?根據(jù)計(jì)算結(jié)果,輸出判斷情況?*/
????
????double?x0;
????
????int?Newton(double(*)(double)double(*)(double)double?&x0);
????
????x0?=?0.6;
????
????b?=?Newton(ff1x0);
????
????if(?b?=?1?)???printf(“\n\nThe?root?of?is?x=%f\n\n“x0);
??????
????else?errormess(b);
}
int?Newton(?double(*f)(double)?double(*f1)(double)?double?&x0?)
{
int?k?=?0;
????double?t?=?1.0;
????double?xk;
printf(“k\t\t???t\t\t???xk\t\t??f(xk)\n“);
printf(“--------------------------------------------------------------------------------“);
????printf(“%d\t\t\t\t%f\t%f\t\t\t“kx0f(x0));
????
????xk?=?x0?-?t*(??f(x0)/f1(x0)?)
- 上一篇:三菱PLC 串口通信程序
- 下一篇:北京浮生記控制臺(tái)版C++源代碼
評(píng)論
共有 條評(píng)論