C#,数值计算——插值和外推,Powvargram的计算方法与源程序

1 文本格式

using System;

namespace Legalsoft.Truffer

{

/// <summary>

/// Functor for variogram v(r)=ar^b,

/// where b is specified, a is fitted from the data.

/// </summary>

public class Powvargram

{

private double alph { get; set; }

private double bet { get; set; }

private double nugsq { get; set; }

public Powvargram(double[,] x, double[] y, double beta = 1.5, double nug = 0.0)

{

this.bet = beta;

this.nugsq = nug * nug;

int npt = x.GetLength(0);

int ndim = x.GetLength(1);

double num = 0.0;

double denom = 0.0;

for (int i = 0; i < npt; i++)

{

for (int j = i + 1; j < npt; j++)

{

double rb = 0.0;

for (int k = 0; k < ndim; k++)

{

rb += Globals.SQR(x[i, k] - x[j, k]);

}

rb = Math.Pow(rb, 0.5 * beta);

num += rb * (0.5 * Globals.SQR(y[i] - y[j]) - nugsq);

denom += Globals.SQR(rb);

}

}

alph = num / denom;

}

public double functorMethod(double r)

{

return nugsq + alph * Math.Pow(r, bet);

}

}

}

2 代码格式

cs 复制代码
using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// Functor for variogram v(r)=ar^b, 
    /// where b is specified, a is fitted from the data.
    /// </summary>
    public class Powvargram
    {
        private double alph { get; set; }
        private double bet { get; set; }
        private double nugsq { get; set; }

        public Powvargram(double[,] x, double[] y, double beta = 1.5, double nug = 0.0)
        {
            this.bet = beta;
            this.nugsq = nug * nug;

            int npt = x.GetLength(0);
            int ndim = x.GetLength(1);
            double num = 0.0;
            double denom = 0.0;
            for (int i = 0; i < npt; i++)
            {
                for (int j = i + 1; j < npt; j++)
                {
                    double rb = 0.0;
                    for (int k = 0; k < ndim; k++)
                    {
                        rb += Globals.SQR(x[i, k] - x[j, k]);
                    }
                    rb = Math.Pow(rb, 0.5 * beta);
                    num += rb * (0.5 * Globals.SQR(y[i] - y[j]) - nugsq);
                    denom += Globals.SQR(rb);
                }
            }
            alph = num / denom;
        }

        public double functorMethod(double r)
        {
            return nugsq + alph * Math.Pow(r, bet);
        }
    }
}
相关推荐
Dream_Snowar1 小时前
速通Python 第三节
开发语言·python
XH华1 小时前
初识C语言之二维数组(下)
c语言·算法
南宫生1 小时前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论
不想当程序猿_2 小时前
【蓝桥杯每日一题】求和——前缀和
算法·前缀和·蓝桥杯
高山我梦口香糖2 小时前
[react]searchParams转普通对象
开发语言·前端·javascript
落魄君子2 小时前
GA-BP分类-遗传算法(Genetic Algorithm)和反向传播算法(Backpropagation)
算法·分类·数据挖掘
菜鸡中的奋斗鸡→挣扎鸡2 小时前
滑动窗口 + 算法复习
数据结构·算法
信号处理学渣2 小时前
matlab画图,选择性显示legend标签
开发语言·matlab
红龙创客2 小时前
某狐畅游24校招-C++开发岗笔试(单选题)
开发语言·c++
Lenyiin2 小时前
第146场双周赛:统计符合条件长度为3的子数组数目、统计异或值为给定值的路径数目、判断网格图能否被切割成块、唯一中间众数子序列 Ⅰ
c++·算法·leetcode·周赛·lenyiin