Keyword: 連続関数の根
概要
本サンプルは連続関数の根を求めるC#によるサンプルプログラムです。 本サンプルは許容誤差を1.0e-5とする、区間[1,0]の範囲内の以下の連続関数の根の近似を求めて出力します。非線形補間法、外挿法、二分法を組み合わせた手法が使用されています。
※本サンプルはnAG Library for .NETに含まれる関数 c05ad() のExampleコードです。本サンプル及び関数の詳細情報は c05ad のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
出力結果
(本関数の詳細はc05ad のマニュアルページを参照)- 3行目に連続関数の根が出力されています。
ソースコード
(本関数の詳細はc05ad のマニュアルページを参照)
※本サンプルソースコードは .NET環境用の科学技術・統計計算ライブラリである「nAG Library for .NET」の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
// c05ad Example Program Text
// C# version, nAG Copyright 2008
using System;
using NagLibrary;
namespace NagDotNetExamples
{
public class C05ADE
{
static void Main(String[] args)
{
StartExample();
}
public static void StartExample()
{
try
{
C05.C05AD_F fC05AD = new C05.C05AD_F(f);
double a, b, eps, eta, x; int ifail; Console.WriteLine("c05ad Example Program Results");
a = 0.00e0;
b = 1.00e0;
eps = 1.00e-5;
eta = 0.00e0;
//
C05.c05ad(a, b, eps, eta, fC05AD, out x, out ifail);
//
Console.WriteLine("");
if (ifail == 0)
{
Console.WriteLine(" {0}{1,12:f5}","Zero at x =",x);
}
else
{
Console.WriteLine(" {0}{1,5}"," ** c05ad returned with ifail = ",ifail);
if ((ifail == 2) || (ifail == 3))
{
Console.WriteLine(" {0}{1,12:f5}","Final point = ",x);
}
}
//
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Exception Raised");
}
Console.WriteLine("");
}
//
//
public static double f (double x)
{
double fValue;
fValue = Math.Exp( -x) - x;
return fValue;
}
}
}
