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

    }
}
相关推荐
星星法术嗲人11 分钟前
【Java】—— 集合框架:Collections工具类的使用
java·开发语言
Eric.Lee202124 分钟前
数据集-目标检测系列- 螃蟹 检测数据集 crab >> DataBall
python·深度学习·算法·目标检测·计算机视觉·数据集·螃蟹检测
黑不溜秋的25 分钟前
C++ 语言特性29 - 协程介绍
开发语言·c++
一丝晨光30 分钟前
C++、Ruby和JavaScript
java·开发语言·javascript·c++·python·c·ruby
天上掉下来个程小白32 分钟前
Stream流的中间方法
java·开发语言·windows
林辞忧33 分钟前
算法修炼之路之滑动窗口
算法
xujinwei_gingko43 分钟前
JAVA基础面试题汇总(持续更新)
java·开发语言
￴ㅤ￴￴ㅤ9527超级帅44 分钟前
LeetCode hot100---二叉树专题(C++语言)
c++·算法·leetcode
liuyang-neu1 小时前
力扣 简单 110.平衡二叉树
java·算法·leetcode·深度优先
penguin_bark1 小时前
LCR 068. 搜索插入位置
算法·leetcode·职场和发展