非線形方程式を解くための数値法二分法


厳密にScience Pressの数値計算方法に従って、区間[1,2]のルートで非線形方程式y = x ^ 3 + 4 * x ^ 2-10を小数点以下第3位まで正確に解きます


#include <iostream>
using namespace std;
#define WUCHA 0.0005//误差
double hanshu(double x) {//函数
	return x * x * x + x * x * 4.0 - 10.0;
}

int main()
{
	double a = 1;
	double b = 2;
	double midd;
	int count = 1;
	while ((b - a)/2 > WUCHA) {
		midd = (a + b) / 2;
		if (hanshu(midd) > 0.0) {
			b=midd;
		}
		else {
			a=midd;
		}
		count++;
		
	}
	cout << "结果:" << (a+b)/2 << endl;
	cout << "运算次数:" << count;
	return 0;
}

}

ここに画像の説明を挿入

元の記事を30件公開 9 件を獲得 1332件を訪問

おすすめ

転載: blog.csdn.net/weixin_43625164/article/details/104613250