43 lines
943 B
C#
43 lines
943 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace BotSharp.Algorithm.HiddenMarkovModel.MathHelpers
|
|
{
|
|
public class PolynomialHelper
|
|
{
|
|
/// <summary>
|
|
/// Evaluates polynomial of degree N
|
|
/// </summary>
|
|
///
|
|
public static double Polevl(double x, double[] coef, int n)
|
|
{
|
|
double ans;
|
|
|
|
ans = coef[0];
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
ans = ans * x + coef[i];
|
|
|
|
return ans;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Evaluates polynomial of degree N with assumption that coef[N] = 1.0
|
|
/// </summary>
|
|
///
|
|
public static double P1evl(double x, double[] coef, int n)
|
|
{
|
|
double ans;
|
|
|
|
ans = x + coef[0];
|
|
|
|
for (int i = 1; i < n; i++)
|
|
ans = ans * x + coef[i];
|
|
|
|
return ans;
|
|
}
|
|
}
|
|
}
|