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];
                }
            }
        }

    }
}
相关推荐
zhangyao9403304 分钟前
关于js导入Excel时,Excel的(年/月/日)日期是五位数字的问题。以及对Excel日期存在的错误的分析和处理。
开发语言·javascript·excel
骑驴看星星a11 分钟前
【Three.js--manual script】4.光照
android·开发语言·javascript
星释1 小时前
Rust 练习册 :Leap与日期计算
开发语言·后端·rust
智驱力人工智能3 小时前
基于视觉分析的人脸联动使用手机检测系统 智能安全管理新突破 人脸与手机行为联动检测 多模态融合人脸与手机行为分析模型
算法·安全·目标检测·计算机视觉·智能手机·视觉检测·边缘计算
悟能不能悟3 小时前
java的java.sql.Date和java.util.Date的区别,应该怎么使用
java·开发语言
2301_764441333 小时前
水星热演化核幔耦合数值模拟
python·算法·数学建模
循环过三天3 小时前
3.4、Python-集合
开发语言·笔记·python·学习·算法
_院长大人_5 小时前
设计模式-工厂模式
java·开发语言·设计模式
MATLAB代码顾问5 小时前
MATLAB实现决策树数值预测
开发语言·决策树·matlab
priority_key5 小时前
排序算法:堆排序、快速排序、归并排序
java·后端·算法·排序算法·归并排序·堆排序·快速排序