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(xi, k - xj, k);

}

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

num += rb * (0.5 * Globals.SQR(yi - yj) - 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);
        }
    }
}
相关推荐
运维大师10 分钟前
【K8S 运维实战】31-Helm包管理
运维·算法·kubernetes
烬羽23 分钟前
一个队列,怎么让滑动窗口从 O(nk) 变 O(n)?单调队列彻底搞懂
javascript·数据结构·算法
Alex Gram26 分钟前
双机热备软件哪个好
java·系统架构·c#·keepalived·高可用·双机热备·双机热备软件
末代iOS程序员华仔27 分钟前
OPC + Flutter + Swift:跨平台应用上架与专业知识点获客实战指南
开发语言·flutter·swift
脚踏实地皮皮晨28 分钟前
003004002_UniformGrid控件的使用方法
开发语言·c#·.net·wpf·visual studio
XH华30 分钟前
C++语言第四章:模板初阶
数据结构·c++·算法
纳兰青华32 分钟前
拼图大师:从“暴力尝试“到“动态规划“的拆字艺术
java·算法·动态规划
星马梦缘40 分钟前
算法设计导论 课堂笔记
算法·动态规划·分治·时间复杂度·最优二叉树
j7~2 小时前
【Linux】二十六.线程篇三《Linux多线程编程:线程控制、线程ID以及进程地址空间分布、线程局部存储__thread以及clone系统调用》---详解
linux·运维·服务器·开发语言·c++·多线程编辑·线程的控制
维吉斯蔡9 小时前
【VS Code / Cursor】文件夹右键快捷打开与文件类型自动关联
开发语言·程序人生·学习方法