⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runge-kutta.h

📁 四种方法求积分:runge-kutta法
💻 H
字号:
#include "iostream.h"
#include "math.h"

rungekutta(double h, double xstart, double y, double xend)
{
	double x = xstart, k1, k2, k3, k4;
	for(int i = 0; i < (xend - xstart) / h; i++)
	{
		k1 = feuler(x, y);
		k2 = feuler(x + h / 2, y + h * k1 / 2);
		k3 = feuler(x + h / 2, y + h * k2 / 2);
		k4 = feuler(x + h, y + h * k3);
		y = y + h * (k1 + 2 * k2 + 2 * k3 + k4) / 6;

		x += h;
		double ytemp = 1 / (1 + x * x);
		cout << i + 1 << "\t" << x << "\t" << y << "\t" << ytemp << "\t" << sqrt((y - ytemp)*(y - ytemp)) << endl;
	}

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -