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 f0..m - 10..n - 1, with the corresponding abscissas

/// in t0..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 doublem;

double, a = new doublem, m;

t0 = t0;

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

{

fk, 0 = g(k, t0);

}

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

{

ti = ti - 1 + h;

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

{

double sum = g(k, ti);

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

{

sum += 0.5 * h * ak(k, l, ti, t0) * fl, 0;

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

{

sum += h * ak(k, l, ti, tj) * fl, j;

}

if (k == l)

{

ak, l = 1.0 - 0.5 * h * ak(k, l, ti, ti);

}

else

{

ak, l = -0.5 * h * ak(k, l, ti, ti);

}

}

bk = sum;

}

LUdcmp alu = new LUdcmp(a);

alu.solve( b, b);

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

{

fk, i = bk;

}

}

}

}

}

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

    }
}
相关推荐
牛奔3 小时前
Go 如何打印调试深层或嵌套的结构体
开发语言·后端·golang
m沐沐3 小时前
【深度学习】YOLOv2目标检测算法——改进点、网络结构与聚类先验框解析
人工智能·pytorch·深度学习·算法·yolo·目标检测·transformer
不会就选b3 小时前
算法日常・每日刷题--<链表>3
数据结构·算法·链表
geovindu4 小时前
go: Iterative Algorithms
开发语言·后端·算法·golang·迭代算法
学逆向的4 小时前
汇编——JCC指令
开发语言·汇编·网络安全
mayaairi4 小时前
JS循环语句深度解析:嵌套for、while与do...while
开发语言·前端·javascript
kite01215 小时前
Go语言Map深度解析与最佳实践
开发语言·后端·golang
Zachery Pole6 小时前
CCF-CSP备战NO.7【队列】
算法
闪电悠米6 小时前
力扣hot100-48.旋转图像-转置翻转详解
算法·leetcode·职场和发展
满天星83035776 小时前
【算法】最长递增子序列(三种解法)
算法