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

编程入门 行业动态 更新时间:2024-10-13 22:23:28

C#,数值计算——求解一组m维线性Volterra<a href=https://www.elefans.com/category/jswz/34/1716210.html style=方程组的计算方法与源程序"/>

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 代码格式

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

更多推荐

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

本文发布于:2023-11-30 13:33:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方程组   源程序   线性   数值   计算方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!