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

    }
}
相关推荐
若亦_Royi23 分钟前
C++ 的大括号的用法合集
开发语言·c++
Captain823Jack1 小时前
nlp新词发现——浅析 TF·IDF
人工智能·python·深度学习·神经网络·算法·自然语言处理
资源补给站1 小时前
大恒相机开发(2)—Python软触发调用采集图像
开发语言·python·数码相机
Captain823Jack1 小时前
w04_nlp大模型训练·中文分词
人工智能·python·深度学习·神经网络·算法·自然语言处理·中文分词
m0_748247552 小时前
Web 应用项目开发全流程解析与实战经验分享
开发语言·前端·php
6.942 小时前
Scala学习记录 递归调用 练习
开发语言·学习·scala
是小胡嘛2 小时前
数据结构之旅:红黑树如何驱动 Set 和 Map
数据结构·算法
m0_748255022 小时前
前端常用算法集合
前端·算法
FF在路上2 小时前
Knife4j调试实体类传参扁平化模式修改:default-flat-param-object: true
java·开发语言
呆呆的猫3 小时前
【LeetCode】227、基本计算器 II
算法·leetcode·职场和发展