[ 簡単な説明 ] 常微分方程式ライブラリの使用例です。 常微分方程式を表す関数(_fxy( ) 及び _fmxy( ) )には、dy/dx = f(x, y) で表される右辺の式を定義します。 注 : 本プログラム例では、_fxy( ) の中で変数 x を、_fmxy( ) の中で変数 multi を使用していませんので、 コンパイル時に警告が出るかもしれませんが、無視して構いません。 |
/* test27.c */ #include <stdio.h> #include "sslib.h" double _fxy(double x, double y); void _fmxy(double x, double y[], double dif[], int multi); double _fxy(double x, double y) { return y + 1.0; } void _fmxy(double x, double y[], double dif[], int multi) { dif[0] = y[1] + 1.0; dif[1] = y[0]; } int main(void) { double r[50], y[100]; double a, b, c, e, exact1, exact2, x, xi, xe, x0, y0, y1, h; int error, i, multi, n; n = 20; x0 = y0 = 0.0; h = 0.05; error = rngkg(x0, y0, n, h, y); printf("Solution Ordinary Differential Equation\n"); printf(" by Runge-Kutta-Gill method\n"); printf(" Result = %13.10g\n", y[n]); printf(" Exact = %13.10g\n", exp(1.0) - 1.0); printf(" Error = %5d\n", error); n = 20; x0 = y0 = 0.0; h = 0.05; error = hamng(x0, y0, n, h, y); printf("\nSolution Ordinary Differential Equation\n"); printf(" by Hamming method\n"); printf(" Result = %13.10g\n", y[n]); printf(" Exact = %13.10g\n", exp(1.0) - 1.0); printf(" Error = %5d\n", error); n = 20; x = 0.0; y[0] = 0.0; y[1] = 1.0; h = 0.05; multi = 2; error = rngkgm(x, y, h, multi, n); exact1 = exp(1.0) - exp(-1.0); exact2 = exp(1.0) + exp(-1.0) - 1.0; printf("\nSolution Ordinary Differential Multiple Equation\n"); printf(" by Runge-Kutta-Gill method\n"); printf(" Result = %13.10g, %13.10g\n", y[0], y[1]); printf(" Exact = %13.10g, %13.10g\n", exact1, exact2); printf(" Error = %5d\n", error); return 1; } |
Solution Ordinary Differential Equation by Runge-Kutta-Gill method Result = 1.718281693 Exact = 1.718281828 Error = 0 Solution Ordinary Differential Equation by Hamming method Result = 1.718281693 Exact = 1.718281828 Error = 0 Solution Ordinary Differential Multiple Equation by Runge-Kutta-Gill method Result = 2.350402232, 2.086161154 Exact = 2.350402387, 2.08616127 Error = 0 |