当前位置: 首页 > news >正文

C#,数值计算——函数计算,Epsalg的计算方法与源程序

1 文本格式

using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// Convergence acceleration of a sequence by the algorithm.Initialize by
    /// calling the constructor with arguments nmax, an upper bound on the
    /// number of terms to be summed, and epss, the desired accuracy.Then make
    /// successive calls to the function next, with argument the next partial sum
    /// of the sequence. The current estimate of the limit of the sequence is 
    /// returned by next.The flag cnvgd is set when convergence is detected.
    /// </summary>
    public class Epsalg
    {
        private double[] e { get; set; }
        private int n { get; set; }
        private int ncv { get; set; }
        public bool cnvgd { get; set; }
        /// <summary>
        /// Numbers near machine underflow and overflow limits.
        /// </summary>
        private double eps { get; set; }
        private double small { get; set; }
        private double big { get; set; }
        private double lastval { get; set; }
        private double lasteps { get; set; }

        public Epsalg(int nmax, double epss)
        {
            this.e = new double[nmax];
            this.n = 0;
            this.ncv = 0;
            this.cnvgd = false;
            this.eps = epss;
            this.lastval = 0.0;
            small = float.MinValue * 10.0;
            big = double.MaxValue;
        }

        public double next(double sum)
        {
            e[n] = sum;
            double temp2 = 0.0;
            for (int j = n; j > 0; j--)
            {
                double temp1 = temp2;
                temp2 = e[j - 1];
                double diff = e[j] - temp2;
                if (Math.Abs(diff) <= small)
                {
                    e[j - 1] = big;
                }
                else
                {
                    e[j - 1] = temp1 + 1.0 / diff;
                }
            }
            n++;
            double val = (n & 1) != 0 ? e[0] : e[1];
            if (Math.Abs(val) > 0.01 * big)
            {
                val = lastval;
            }
            lasteps = Math.Abs(val - lastval);
            if (lasteps > eps)
            {
                ncv = 0;
            }
            else
            {
                ncv++;
            }
            if (ncv >= 3)
            {
                cnvgd = true;
            }
            return (lastval = val);
        }

    }
}
 

2 代码格式

using System;namespace Legalsoft.Truffer
{/// <summary>/// Convergence acceleration of a sequence by the algorithm.Initialize by/// calling the constructor with arguments nmax, an upper bound on the/// number of terms to be summed, and epss, the desired accuracy.Then make/// successive calls to the function next, with argument the next partial sum/// of the sequence. The current estimate of the limit of the sequence is /// returned by next.The flag cnvgd is set when convergence is detected./// </summary>public class Epsalg{private double[] e { get; set; }private int n { get; set; }private int ncv { get; set; }public bool cnvgd { get; set; }/// <summary>/// Numbers near machine underflow and overflow limits./// </summary>private double eps { get; set; }private double small { get; set; }private double big { get; set; }private double lastval { get; set; }private double lasteps { get; set; }public Epsalg(int nmax, double epss){this.e = new double[nmax];this.n = 0;this.ncv = 0;this.cnvgd = false;this.eps = epss;this.lastval = 0.0;small = float.MinValue * 10.0;big = double.MaxValue;}public double next(double sum){e[n] = sum;double temp2 = 0.0;for (int j = n; j > 0; j--){double temp1 = temp2;temp2 = e[j - 1];double diff = e[j] - temp2;if (Math.Abs(diff) <= small){e[j - 1] = big;}else{e[j - 1] = temp1 + 1.0 / diff;}}n++;double val = (n & 1) != 0 ? e[0] : e[1];if (Math.Abs(val) > 0.01 * big){val = lastval;}lasteps = Math.Abs(val - lastval);if (lasteps > eps){ncv = 0;}else{ncv++;}if (ncv >= 3){cnvgd = true;}return (lastval = val);}}
}

http://www.lryc.cn/news/225481.html

相关文章:

  • Delphi 12 重返雅典 (RAD Studio 12)
  • 手写链表C++
  • 为什么我一直是机器视觉调机仔,为什么一定要学一门高级语言编程?
  • MongoDB单实例安装(Linux)
  • 各种业务场景调用API代理的API接口教程(附带电商平台api接口商品详情数据接入示例)
  • React-hooks有哪些 包括用法是什么?
  • 根据DataFrame指定的列该列中如果有n个不同元素则将其转化为n行显示explode()
  • 《持续交付:发布可靠软件的系统方法》- 读书笔记(十三)
  • 【Copilot】登录报错 Extension activation failed: “No auth flow succeeded.“(VSCode)
  • uboot - 驱动开发 - dw watchdog
  • 【系统架构设计】架构核心知识: 2.5 软件测试、系统转换计划、系统维护
  • EXPLAIN详解(MySQL)
  • [PyTorch][chapter 61][强化学习-免模型学习 off-policy]
  • 【服务器学习】 iomanager IO协程调度模块
  • 前端设计模式之【迭代器模式】
  • Linux-用户与用户组,权限
  • 使用nvm-windows在Windows下轻松管理多个Node.js版本
  • 2023.11.10 hadoop,hive框架概念,基础组件
  • Kubernetes 创建pod的yaml文件-简单版-nginx
  • Git的进阶操作,在idea中部署gie
  • 设计模式-迭代器模式(Iterator)
  • 【计算机网络笔记】Internet网络的网络层——IP协议之IP数据报的结构
  • 【Git】Git的GUI图形化工具ssh协议IDEA集成Git
  • Java中抽象类
  • 18 Linux 阻塞和非阻塞 IO
  • 多因素验证如何让企业邮箱系统登录更安全?
  • 投票助手图文音视频礼物打赏流量主小程序开源版开发
  • 黑客(网络安全)技术——高效自学1.0
  • 8255 boot介绍及bring up经验分享
  • visual studio 启用DPI识别功能