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");
        }

    }
}
相关推荐
张彦峰ZYF2 分钟前
Prefactor 从“看见 Agent”到“拦住 Agent”:实时评估如何重构 AI Agent 的生产可靠性
人工智能·llm·ai agent·evaluate·llm-as-a-judge·prefactor·金融agent
知几蜗牛3 分钟前
语音AI开始边听边说,改变的不只是响应速度
人工智能
xingyuzhisuan5 分钟前
无限画布基本的五个关键问题:产出物、规模、角色、技术、成本
人工智能
知几蜗牛7 分钟前
ChatGPT服务10亿周用户后,最难扩展的可能不是模型
人工智能
Beyond_System|系统之外10 分钟前
ChatGPT5.2_Codex_零基础图文手册(正文 一)
人工智能·codex
大熊背12 分钟前
IspPipeline色相旋转模块实现
人工智能·算法·计算机视觉
爱学习的小白柏13 分钟前
同城双活的核心不是双活,是逼着数据别出机房
大数据·人工智能·算法·langchain·ai编程
Raas10016 分钟前
MAI Gateway(魔芋企业级AI网关)功能全解:AI网关有哪些功能?一文看懂AI网关能力矩阵
大数据·人工智能·矩阵·gateway·mai gateway·企业级产品
千里码aicood16 分钟前
基于Python语言的测量程序设计
开发语言·python
当下新鲜事18 分钟前
高压线束绝缘层在线测径为何成为新能源汽车线束制造的关键工序?简博斯JG-L系列测径仪解析
人工智能·汽车·制造