当前位置: 首页 > 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);}}
}

相关文章:

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 term…...

Delphi 12 重返雅典 (RAD Studio 12)

RAD Studio 12 的新功能&#xff1a; 以最新的平台版本为目标&#xff01; RAD Studio 12 提供对 iOS 17&#xff08;仅适用于 Delphi&#xff09;、Android 14 和 macOS Sonoma 的官方支持。RAD Studio 12 还支持 Ubuntu 22 LTS 和 Windows Server 2022。 Delphi 源代码的多…...

手写链表C++

目录 一、链表基本概念以及注意事项 1.1 构造函数与析构函数 1.2 插入元素 1.3 重载运算符 二、小结 一、链表基本概念以及注意事项 在工作中&#xff0c;链表是一种常见的数据结构&#xff0c;可以用于解决很多实际问题。在学习中&#xff0c;掌握链表可以提高编程能力和…...

为什么我一直是机器视觉调机仔,为什么一定要学一门高级语言编程?

​ 为什么我是机器视觉调机仔&#xff0c;为什么一定要学一门高级语言编程&#xff0c;以后好不好就业&#xff0c;待遇高不高&#xff0c;都是跟这项技术没关系&#xff0c;是跟这个技术背后的行业发展有关系。 你可以选择离机器视觉行业&#xff0c;也可以选择与高级语言相关…...

MongoDB单实例安装(Linux)

实战环境 centos7系统、64位 iptables和selinux关闭 mongodb简介 mongodb是个非关系型数据库&#xff0c;但操作跟关系型数据最类似。mysql是关系型数据库 mongodb是面向文档存储的非关系型数据库&#xff0c;数据以json的格式进行存储 mongodb可用来永久存储&#xff0c;也可用…...

各种业务场景调用API代理的API接口教程(附带电商平台api接口商品详情数据接入示例)

API代理的API接口在各种业务场景中具有广泛的应用&#xff0c;本文将介绍哪些业务场景可以使用API代理的API接口&#xff0c;并提供详细的调用教程和代码演示&#xff0c;同时&#xff0c;我们还将讨论在不同场景下使用API代理的API接口所带来的好处。 哪些业务场景可以使用API…...

React-hooks有哪些 包括用法是什么?

React Hooks是React 16.8版本引入的功能&#xff0c;它允许你在函数组件中使用状态&#xff08;state&#xff09;和其他React特性&#xff0c;而无需编写类组件。以下是一些常用的React Hooks及其用法&#xff1a; 1&#xff1a;useState&#xff1a;用于在函数组件中添加状态…...

根据DataFrame指定的列该列中如果有n个不同元素则将其转化为n行显示explode()

【小白从小学Python、C、Java】 【计算机等考500强证书考研】 【Python-数据分析】 根据DataFrame指定的列 该列中如果有n个不同元素 则将其转化为n行显示 explode() 选择题 以下代码两次输出结果分别为几行&#xff1f; import pandas as pd df pd.DataFrame({种类:[蔬菜,水…...

《持续交付:发布可靠软件的系统方法》- 读书笔记(十三)

持续交付&#xff1a;发布可靠软件的系统方法&#xff08;十三&#xff09; 第 13 章 组件和依赖管理13.1 引言13.2 保持应用程序可发布13.2.1 将新功能隐蔽起来&#xff0c;直到它完成为止13.2.2 所有修改都是增量式的13.2.3 通过抽象来模拟分支 13.3 依赖13.3.1 依赖地狱13.3…...

【Copilot】登录报错 Extension activation failed: “No auth flow succeeded.“(VSCode)

问题描述 Visual Studio Code 登录 GitHub Copilot 插件报错。 在浏览器中成功授权 GitHub 账户&#xff0c;返回 VSCode 后仍然报错。 [ERROR] [default] [2023-11-06T12:34:56.185Z] Extension activation failed: "No auth flow succeeded."原因分析 网络环境问…...

uboot - 驱动开发 - dw watchdog

说明 公司SOC使用的watchdog模块是新思&#xff08;Synopsys&#xff09;的IP。 需求 用户有时会在uboot/kernel中做些开发&#xff0c;新增一些功能&#xff08;OTA升级等&#xff09;&#xff0c;可能会出现uboot/kernel启动崩溃甚至设备死机等问题&#xff0c;需要在uboo…...

【系统架构设计】架构核心知识: 2.5 软件测试、系统转换计划、系统维护

目录 一 软件测试 1 静态测试 2 动态测试 3 测试 4 集成测试的策略 二...

EXPLAIN详解(MySQL)

EXPLAIN概述 EXPLAIN语句提供MySQL如何执行语句的信息。EXPLAIN与SELECT, DELETE, INSERT, REPLACE和UPDATE语句一起工作。 EXPLAIN返回SELECT语句中使用的每个表的一行信息。它按照MySQL在处理语句时读取表的顺序列出了输出中的表。MySQL使用嵌套循环连接方法解析所有连接。…...

[PyTorch][chapter 61][强化学习-免模型学习 off-policy]

前言&#xff1a; 蒙特卡罗的学习基本流程&#xff1a; Policy Evaluation : 生成动作-状态轨迹,完成价值函数的估计。 Policy Improvement: 通过价值函数估计来优化policy。 同策略&#xff08;one-policy&#xff09;&#xff1a;产生 采样轨迹的策略 和要改…...

【服务器学习】 iomanager IO协程调度模块

iomanager IO协程调度模块 以下是从sylar服务器中学的&#xff0c;对其的复习&#xff1b; 参考资料 继承自协程调度器&#xff0c;封装了epoll&#xff0c;支持为socket fd注册读写事件回调函数 IO协程调度还解决了调度器在idle状态下忙等待导致CPU占用率高的问题。IO协程调…...

前端设计模式之【迭代器模式】

文章目录 前言介绍实现接口优缺点应用场景后言 前言 hello world欢迎来到前端的新世界 &#x1f61c;当前文章系列专栏&#xff1a;前端设计模式 &#x1f431;‍&#x1f453;博主在前端领域还有很多知识和技术需要掌握&#xff0c;正在不断努力填补技术短板。(如果出现错误&a…...

Linux-用户与用户组,权限

1.用户组管理&#xff08;以下命令需root用户执行&#xff09; ①创建用户组 groupadd 用户组名 ②删除用户组 groupdel 用户组名 2.用户管理&#xff08;以下命令需root用户执行&#xff09; ①创建用户 useradd [-g -d] 用户名 >-g&#xff1a;指定用户的组&#xff0c;不…...

使用nvm-windows在Windows下轻松管理多个Node.js版本

Node.js是一个非常流行的JavaScript运行时环境&#xff0c;许多开发者在开发过程中可能需要在不同的Node.js版本之间进行切换。在Windows操作系统下&#xff0c;我们可以使用nvm-windows来轻松管理多个Node.js版本。本文将详细介绍如何安装和使用nvm-windows。 什么是nvm-wind…...

2023.11.10 hadoop,hive框架概念,基础组件

目录 分布式和集群的概念: hadoop架构的三大组件:Hdfs,MapReduce,Yarn 1.hdfs 分布式文件存储系统 Hadoop Distributed File System 2.MapReduce 分布式计算框架 3.Yarn 资源调度管理框架 三个组件的依赖关系是: hive数据仓库处理工具 hive的大体流程: Apache hive的…...

Kubernetes 创建pod的yaml文件-简单版-nginx

apiVersion: v1 #api文档版本 kind: Pod # 资源类型 Deployment,StatefulSet之类 metadata: #pod元数据 描述信息 name: nginx-demo labels: type: app #自定义标签 version: 1.0.0 # 自定义pod版本 namespace: default spec: #期望Pod按照这里的描述创建 cont…...

Lenovo Legion Toolkit:拯救者笔记本的终极性能控制中心

Lenovo Legion Toolkit&#xff1a;拯救者笔记本的终极性能控制中心 【免费下载链接】LenovoLegionToolkit Lightweight Lenovo Vantage and Hotkeys replacement for Lenovo Legion laptops. 项目地址: https://gitcode.com/gh_mirrors/le/LenovoLegionToolkit 想要完全…...

FanControl终极配置指南:Windows平台精准散热控制解决方案

FanControl终极配置指南&#xff1a;Windows平台精准散热控制解决方案 【免费下载链接】FanControl.Releases This is the release repository for Fan Control, a highly customizable fan controlling software for Windows. 项目地址: https://gitcode.com/GitHub_Trendin…...

SeqGPT-560M企业知识图谱构建:从非结构化文本中抽取实体关系三元组

SeqGPT-560M企业知识图谱构建&#xff1a;从非结构化文本中抽取实体关系三元组 1. 项目概述 SeqGPT-560M是一个专门为企业知识图谱构建设计的智能信息抽取系统。与通用的聊天对话模型不同&#xff0c;这个系统专注于一件事&#xff1a;从各种非结构化文本中精准提取实体和关系…...

3个妙招解决FasterWhisperGUI在Windows系统安装后无法启动的难题

3个妙招解决FasterWhisperGUI在Windows系统安装后无法启动的难题 【免费下载链接】faster-whisper-GUI faster_whisper GUI with PySide6 项目地址: https://gitcode.com/gh_mirrors/fa/faster-whisper-GUI FasterWhisperGUI是一个基于PySide6开发的图形界面工具&#x…...

新手避坑指南:用PHPStudy在Windows上快速搭建Pikachu靶场(附常见错误解决)

新手避坑指南&#xff1a;用PHPStudy在Windows上快速搭建Pikachu靶场&#xff08;附常见错误解决&#xff09; 在网络安全学习的过程中&#xff0c;搭建本地靶场环境是每个初学者必须掌握的技能。Pikachu靶场作为一个专为Web安全学习设计的漏洞演示平台&#xff0c;包含了SQL注…...

幻境·流金科研辅助:论文插图生成、数据可视化美学增强、期刊格式适配

幻境流金科研辅助&#xff1a;论文插图生成、数据可视化美学增强、期刊格式适配 想象一下这个场景&#xff1a;深夜的实验室里&#xff0c;你刚刚完成了一组复杂的数据分析&#xff0c;结果非常漂亮。但当你打开论文草稿&#xff0c;准备插入图表时&#xff0c;面对那些千篇一…...

Intv_ai_mk11 算法优化解析:深入理解LSTM在对话生成中的应用

Intv_ai_mk11 算法优化解析&#xff1a;深入理解LSTM在对话生成中的应用 1. 为什么LSTM在对话生成中如此重要 想象一下你和朋友聊天时&#xff0c;突然忘记对方刚才说了什么&#xff0c;对话就会变得支离破碎。传统RNN&#xff08;循环神经网络&#xff09;就像这个健忘的朋友…...

破茧成蝶:2026全栈技术趋势全景——TypeScript、Rust、AI Agent、云原生与边缘计算的深度融合

引言&#xff1a;站在时代交汇点的全栈工程师 2026年&#xff0c;我们正站在一个前所未有的技术奇点之上。过去五年&#xff0c;技术浪潮以前所未有的速度和深度重塑了软件开发的每一个环节。从前端到后端&#xff0c;从云端到设备边缘&#xff0c;从人工编码到AI自主执行&…...

postgresql15 postgresql.cof-data_directory

在postgresql里&#xff0c;data_directory指的是数据库实例的数据目录&#xff0c;也就是postgresql存放数据文件、WAL、配置文件(部分)的地方。data_directory参数值的修改&#xff0c;需要重启postgresql才能生效。如何查看当前data_directory&#xff1a;-bash-4.2$ psql p…...

RimWorld高级性能优化:Performance Fish深度解析与实战配置教程

RimWorld高级性能优化&#xff1a;Performance Fish深度解析与实战配置教程 【免费下载链接】Performance-Fish Performance Mod for RimWorld 项目地址: https://gitcode.com/gh_mirrors/pe/Performance-Fish Performance Fish是RimWorld社区中备受推崇的性能优化模组&…...