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.mfbz.cn/a/130935.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

软件工程的舞台上,《人月神话》的美学纷飞

前言&#xff1a; Hello大家好&#xff0c;我是Dream。 今天给大家分享一本书&#xff1a;《人月神话》——软件工程的经典之作。 《人月神话》是一本具有深远影响力的软件工程著作&#xff0c;无论是软件开发者、管理者还是学习软件工程的人士&#xff0c;都能从中获得宝贵的启…

高性能网络编程 - 解读3种线程模型

文章目录 Pre线程模型1&#xff1a;传统阻塞 I/O 服务模型线程模型2&#xff1a;Reactor 模式Reactor 模式的基本设计思想Reactor 模式中的关键组成3种典型实现单 Reactor 单线程单 Reactor 多线程主从 Reactor 多线程 小结 线程模型3&#xff1a;Proactor 模型 Pre 高性能网络…

深入理解 TCP;场景复现,掌握鲜为人知的细节

握手失败 第一次握手丢失了&#xff0c;会发生什么&#xff1f; 当客户端想和服务端建立 TCP 连接的时候&#xff0c;首先第一个发的就是 SYN 报文&#xff0c;然后进入到 SYN_SENT 状态。 在这之后&#xff0c;如果客户端迟迟收不到服务端的 SYN-ACK 报文&#xff08;第二次…

管易云与电商平台的无代码集成:实现API连接与用户运营

管易云简介及其与电商平台的合作 金蝶管易云是金蝶集团旗下以电商为核心业务的子公司&#xff0c;是国内最早的电商ERP服务商之一&#xff0c;总部在上海&#xff0c;与淘宝、天猫、 京东、拼多多、抖音等300多家主流电商平台建立合作关系&#xff0c;同时管易云是互联网平台首…

MATLAB中deconvwnr函数用法

目录 语法 说明 示例 使用 Wiener 滤波对图像进行去模糊处理 deconvwnr函数的功能是使用 Wiener 滤波对图像进行去模糊处理。 语法 J deconvwnr(I,psf,nsr) J deconvwnr(I,psf,ncorr,icorr) J deconvwnr(I,psf) 说明 J deconvwnr(I,psf,nsr) 使用 Wiener 滤波算法对…

操作系统 | 编写内核

&#x1f308;个人主页&#xff1a;Sarapines Programmer&#x1f525; 系列专栏&#xff1a;《操作系统实验室》&#x1f516;少年有梦不应止于心动&#xff0c;更要付诸行动。 目录结构 1. 操作系统实验之编写内核 1.1 实验目的 1.2 实验内容 1.3 实验步骤 1.4 实验过程 …

1.linux极速进阶

目录 概述文件相关vi文件编辑查找字符串查找某一行内容复制粘贴快速删除快速跳到文件首行和末行 进程相关ps/netstatjpstopkill linux三剑客grepsed添加方面操作删除方面替换操作 awk 结束 概述 身为后端开发&#xff0c;大数据平台搭建&#xff0c;对 linux 系统的操作最起码…

高阶组件和Hooks

目录 1. 高阶组件&#xff08;Higher-Order Components&#xff09; 1.1 创建高阶组件 1.2 使用高阶组件 2. Hooks 2.1 使用useState Hook管理状态 2.2 创建自定义Hook 结论 1. 高阶组件&#xff08;Higher-Order Components&#xff09; 高阶组件是一个接受一个组件作为…

面向对象--------三巨头

꒰˃͈꒵˂͈꒱ write in front ꒰˃͈꒵˂͈꒱ ʕ̯•͡˔•̯᷅ʔ大家好&#xff0c;我是xiaoxie.希望你看完之后,有不足之处请多多谅解&#xff0c;让我们一起共同进步૮₍❀ᴗ͈ . ᴗ͈ ა 本文由xiaoxieʕ̯•͡˔•̯᷅ʔ 原创 CSDN 如需转载还请通知˶⍤⃝˶个人主页&am…

Apache Airflow (四) :Airflow 调度shell命令

&#x1f3e1; 个人主页&#xff1a;IT贫道_大数据OLAP体系技术栈,Apache Doris,Clickhouse 技术-CSDN博客 &#x1f6a9; 私聊博主&#xff1a;加入大数据技术讨论群聊&#xff0c;获取更多大数据资料。 &#x1f514; 博主个人B栈地址&#xff1a;豹哥教你大数据的个人空间-豹…

Unity 制作血量滑动条(Slider)

1.创建UI slider 层级面板点击右键-UI-slider 2.调整UI位置 选择2D视图&#xff0c;调整锚点和滑动条位置 3.PS中制作UI 导出2个图层&#xff0c;PNG格式。 4.改成精灵模式&#xff08;sprite2d&#xff09; 把两个PNG导入Unity仓库中&#xff0c;选中两个图&#xff0c;右…

【LeetCode刷题笔记】堆和优先级队列

358. K 距离间隔重排字符串 解题思路: 大根堆 + 队列 , 1)首先 计数数组 统计 每个字符出现的次数 ,然后将 计数 > 0 的 字符 和 次数 一起放入 大根堆 ,大根堆中

Matlab的多项式留数与极点的计算

Matlab的多项式留数与极点的计算 以下面的多项式为例&#xff1a; 运算代码&#xff1a; clc clear closesyms p % 定义多项式 Zp(5*p^571*p^370*p)/(2*p^635*p^4117*p^236); % 提取分子与分母 [I,D]numden(Zp); Idouble(coeffs(I,p,"All"));%分子 Ddouble(coeffs…

Git系列之Git集成开发工具及git扩展使用

&#x1f389;&#x1f389;欢迎来到我的CSDN主页&#xff01;&#x1f389;&#x1f389; &#x1f3c5;我是君易--鑨&#xff0c;一个在CSDN分享笔记的博主。&#x1f4da;&#x1f4da; &#x1f31f;推荐给大家我的博客专栏《Git实战开发》。&#x1f3af;&#x1f3af; &a…

基于若依的ruoyi-nbcio流程管理系统仿钉钉流程json转bpmn的flowable的xml格式(支持并行网关)

更多ruoyi-nbcio功能请看演示系统 gitee源代码地址 前后端代码&#xff1a; https://gitee.com/nbacheng/ruoyi-nbcio 演示地址&#xff1a;RuoYi-Nbcio后台管理系统 这个章节来完成并行网关&#xff0c;前端无需修改&#xff0c;直接后端修改就可以了。 1、并行网关后端修…

C#开发的OpenRA游戏之世界存在的属性CombatDebugOverlay(3)

C#开发的OpenRA游戏之世界存在的属性CombatDebugOverlay(3) 这次来分析CombatDebugOverlay属性,这个属性只有在调试游戏的时候才会使用。当你设置这个属性的时候,就可以看到如下图的结果: 可以看到物品的周边都有一个圆圈,以及有一些十字的点位标志。 那些十字表示的点…

【ATTCK】MITRE Caldera 朴素贝叶斯规划器

CALDERA是一个由python语言编写的红蓝对抗工具&#xff08;攻击模拟工具&#xff09;。它是MITRE公司发起的一个研究项目&#xff0c;该工具的攻击流程是建立在ATT&CK攻击行为模型和知识库之上的&#xff0c;能够较真实地APT攻击行为模式。 通过CALDERA工具&#xff0c;安全…

C++源文件的编译过程 学习 CMake 文档的前置知识

OHHHH&#xff0c;发现自己的基础知识真他妈的是呼呼漏风&#xff0c;&#xff0c;&#xff0c;&#xff0c;&#xff0c;&#xff0c;&#xff0c;&#xff0c;&#xff0c;&#xff0c;&#xff0c; 尴尬得意识到&#xff0c;不仅是英语水平有问题&#xff0c;他码的基础知识…

Web实验总

目录 网站需求&#xff1a; 思路&#xff1a; 实验步骤&#xff1a; 第一步&#xff1a;准备工作 第二步&#xff1a;新建一个存储网页的目录 第三步&#xff1a;修改本地hosts映射 第四步&#xff1a;修改配置文件&#xff0c;建立基于http服务的网站 1)创建用户song和…

iOS移动应用安全加固:保护您的App免受恶意攻击的重要步骤

目录 iOS移动应用安全加固&#xff1a;保护您的App免受恶意攻击的重要步骤 摘要 引言 一、APP加固的概念 二、APP加固方案的比较 三、保护iOS应用的安全 四、总结 参考资料 摘要 本文介绍了移动应用程序&#xff08;App&#xff09;加固的概念和流程&#xff0c;以及市…