C#,数值计算——求解一组m维线性Volterra方程组的计算方法与源程序

1 文本格式

using System;

namespace Legalsoft.Truffer

{

/// <summary>

/// 求解一组m维线性Volterra方程组

/// Solves a set of m linear Volterra equations of the second kind using the

/// extended trapezoidal rule.On input, t0 is the starting point of the

/// integration and h is the step size.g(k, t) is a user-supplied function or

/// functor that returns gk(t), while ak(k, l, t, s) is another user- supplied

/// function or functor that returns the (k, l) element of the matrix K(t, s). The

/// solution is returned in f[0..m - 1][0..n - 1], with the corresponding abscissas

/// in t[0..n - 1], where n-1 is the number of steps to be taken.The value of m is

/// determined from the row-dimension of the solution matrix f.

/// </summary>

public abstract class Volterra

{

public abstract double g(int k, double t);

public abstract double ak(int k, int l, double t1, double t2);

public void voltra(double t0, double h, double[] t, double[,] f)

{

int m = f.GetLength(0);

int n = f.GetLength(1);

double[] b = new double[m];

double[,] a = new double[m, m];

t[0] = t0;

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

{

f[k, 0] = g(k, t[0]);

}

for (int i = 1; i < n; i++)

{

t[i] = t[i - 1] + h;

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

{

double sum = g(k, t[i]);

for (int l = 0; l < m; l++)

{

sum += 0.5 * h * ak(k, l, t[i], t[0]) * f[l, 0];

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

{

sum += h * ak(k, l, t[i], t[j]) * f[l, j];

}

if (k == l)

{

a[k, l] = 1.0 - 0.5 * h * ak(k, l, t[i], t[i]);

}

else

{

a[k, l] = -0.5 * h * ak(k, l, t[i], t[i]);

}

}

b[k] = sum;

}

LUdcmp alu = new LUdcmp(a);

alu.solve( b, b);

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

{

f[k, i] = b[k];

}

}

}

}

}

2 代码格式

cs 复制代码
using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// 求解一组m维线性Volterra方程组
    /// Solves a set of m linear Volterra equations of the second kind using the
    /// extended trapezoidal rule.On input, t0 is the starting point of the
    /// integration and h is the step size.g(k, t) is a user-supplied function or
    /// functor that returns gk(t), while ak(k, l, t, s) is another user- supplied
    /// function or functor that returns the (k, l) element of the matrix K(t, s). The
    /// solution is returned in f[0..m - 1][0..n - 1], with the corresponding abscissas
    /// in t[0..n - 1], where n-1 is the number of steps to be taken.The value of m is
    /// determined from the row-dimension of the solution matrix f.
    /// </summary>
    public abstract class Volterra
    {
        public abstract double g(int k, double t);

        public abstract double ak(int k, int l, double t1, double t2);

        public void voltra(double t0, double h, double[] t, double[,] f)
        {
            int m = f.GetLength(0);
            int n = f.GetLength(1);
            double[] b = new double[m];
            double[,] a = new double[m, m];

            t[0] = t0;
            for (int k = 0; k < m; k++)
            {
                f[k, 0] = g(k, t[0]);
            }
            for (int i = 1; i < n; i++)
            {
                t[i] = t[i - 1] + h;
                for (int k = 0; k < m; k++)
                {
                    double sum = g(k, t[i]);
                    for (int l = 0; l < m; l++)
                    {
                        sum += 0.5 * h * ak(k, l, t[i], t[0]) * f[l, 0];
                        for (int j = 1; j < i; j++)
                        {
                            sum += h * ak(k, l, t[i], t[j]) * f[l, j];
                        }
                        if (k == l)
                        {
                            a[k, l] = 1.0 - 0.5 * h * ak(k, l, t[i], t[i]);
                        }
                        else
                        {
                            a[k, l] = -0.5 * h * ak(k, l, t[i], t[i]);
                        }
                    }
                    b[k] = sum;
                }

                LUdcmp alu = new LUdcmp(a);
                alu.solve( b,  b);
                for (int k = 0; k < m; k++)
                {
                    f[k, i] = b[k];
                }
            }
        }

    }
}
相关推荐
R-G-B1 小时前
【02】C#入门到精通——C# 变量、输入/输出、类型转换
开发语言·c#·c# 变量·c#输入/输出·c#类型转换
星河队长1 小时前
C# 软件加密方法,有使用时间限制,同时要防止拷贝
开发语言·c#
史迪奇_xxx1 小时前
10、一个简易 vector:C++ 模板与 STL
java·开发语言·c++
2301_801252221 小时前
Java中的反射
java·开发语言
Kiri霧1 小时前
Rust开发环境搭建
开发语言·后端·rust
weixin-a153003083161 小时前
[数据抓取-1]beautifulsoup
开发语言·python·beautifulsoup
我不是QI2 小时前
DES 加密算法:核心组件、加解密流程与安全特性
经验分享·算法·安全·网络安全·密码学
前端小刘哥2 小时前
新版视频直播点播EasyDSS平台,让跨团队沟通高效又顺畅
算法
小杨同学yx2 小时前
有关maven的一些知识点
java·开发语言
Aevget2 小时前
DevExpress WinForms v25.1亮点 - PDF Viewer(查看器)等全新升级
pdf·c#·界面控件·winform·devexpress·ui开发