C#,数值计算——偏微分方程,Relaxation的计算方法与源程序

1 文本格式

using System;

namespace Legalsoft.Truffer

{

public class Relaxation

{

private Relaxation() { }

public static void sor(double, a, double, b, double, c, double, d, double, e, double, f, double, u, double rjac)

{

const int MAXITS = 1000;

const double EPS = 1.0e-13;

double anormf = 0.0;

double omega = 1.0;

int jmax = a.GetLength(0);

for (int j = 1; j < jmax - 1; j++)

{

for (int l = 1; l < jmax - 1; l++)

{

anormf += Math.Abs(fj, l);

}

}

for (int n = 0; n < MAXITS; n++)

{

double anorm = 0.0;

int jsw = 1;

for (int ipass = 0; ipass < 2; ipass++)

{

int lsw = jsw;

for (int j = 1; j < jmax - 1; j++)

{

for (int l = lsw; l < jmax - 1; l += 2)

{

double resid = aj, l * uj + 1, l + bj, l * uj - 1, l + cj, l * uj, l + 1 + dj, l * uj, l - 1 + ej, l * uj, l - fj, l;

anorm += Math.Abs(resid);

uj, l -= omega * resid / ej, l;

}

lsw = 3 - lsw;

}

jsw = 3 - jsw;

omega = (n == 0 && ipass == 0 ? 1.0 / (1.0 - 0.5 * rjac * rjac) : 1.0 / (1.0 - 0.25 * rjac * rjac * omega));

}

if (anorm < EPS * anormf)

{

return;

}

}

throw new Exception("MAXITS exceeded");

}

}

}

2 代码格式

cs 复制代码
using System;

namespace Legalsoft.Truffer
{
    public class Relaxation
    {
        private Relaxation() { }

        public static void sor(double[,] a, double[,] b, double[,] c, double[,] d, double[,] e, double[,] f, double[,] u, double rjac)
        {
            const int MAXITS = 1000;
            const double EPS = 1.0e-13;
            double anormf = 0.0;
            double omega = 1.0;
            int jmax = a.GetLength(0);
            for (int j = 1; j < jmax - 1; j++)
            {
                for (int l = 1; l < jmax - 1; l++)
                {
                    anormf += Math.Abs(f[j, l]);
                }
            }
            for (int n = 0; n < MAXITS; n++)
            {
                double anorm = 0.0;
                int jsw = 1;
                for (int ipass = 0; ipass < 2; ipass++)
                {
                    int lsw = jsw;
                    for (int j = 1; j < jmax - 1; j++)
                    {
                        for (int l = lsw; l < jmax - 1; l += 2)
                        {
                            double resid = a[j, l] * u[j + 1, l] + b[j, l] * u[j - 1, l] + c[j, l] * u[j, l + 1] + d[j, l] * u[j, l - 1] + e[j, l] * u[j, l] - f[j, l];
                            anorm += Math.Abs(resid);
                            u[j, l] -= omega * resid / e[j, l];
                        }
                        lsw = 3 - lsw;
                    }
                    jsw = 3 - jsw;
                    omega = (n == 0 && ipass == 0 ? 1.0 / (1.0 - 0.5 * rjac * rjac) : 1.0 / (1.0 - 0.25 * rjac * rjac * omega));
                }
                if (anorm < EPS * anormf)
                {
                    return;
                }
            }
            throw new Exception("MAXITS exceeded");
        }

    }
}
相关推荐
芝麻开门GEO10 分钟前
泰安GEO优化服务,真的能提升效果吗?
人工智能·python
HIT_Weston11 分钟前
104、【Agent】【OpenCode】webfetch 工具提示词
人工智能·agent·opencode
ai_coder_ai11 分钟前
论边缘计算及其应用
人工智能·边缘计算
1892280486112 分钟前
NV023固态MT29F16T08GWLCEJ9-QBES:C
大数据·服务器·人工智能·科技·缓存
Slow菜鸟14 分钟前
AI 代码知识图谱 教程(三)| Understand-Anything(给人看)
人工智能·知识图谱
Cosolar39 分钟前
深度测评 | QoderWork:当 AI 不再只是"聊天搭子",而是真能帮你干活的桌面智能体
人工智能·后端·程序员
明志数科40 分钟前
4D时序标注技术详解:让机器人理解连续动作的数据基础
java·算法·机器人
MartinYeung542 分钟前
[論文學習]大型語言模型的安全與隱私挑戰綜述
人工智能
A10169330711 小时前
从机器翻译到智驾:规则派的黄昏与数据革命的终局(十四)
人工智能·自然语言处理·机器翻译
小小de风呀1 小时前
de风——【从零开始学C++】(十一):list的基本使用和模拟实现
开发语言·c++·list