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);
        }
    }
}
相关推荐
惜棠1 分钟前
visual code + rust入门指南
开发语言·后端·rust
n***i952 分钟前
Rust在嵌入式系统中的内存管理
开发语言·后端·rust
q***06292 分钟前
ThinkPHP和PHP的区别
开发语言·php
小白程序员成长日记17 分钟前
2025.11.23 力扣每日一题
算法·leetcode·职场和发展
Java天梯之路18 分钟前
Java 初学者必看:接口 vs 抽象类,到底有什么区别?
java·开发语言
p***32351 小时前
如何使用C#与SQL Server数据库进行交互
数据库·c#·交互
7***53341 小时前
Rust错误处理模式
开发语言·后端·rust
T***16071 小时前
C++在游戏开发中的AI行为树
开发语言·c++
16_one1 小时前
autoDL安装Open-WebUi+Rag本地知识库问答+Function Calling
人工智能·后端·算法
无心水1 小时前
【Python实战进阶】5、Python字符串终极指南:从基础到高性能处理的完整秘籍
开发语言·网络·python·字符串·unicode·python实战进阶·python工业化实战进阶