博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
龙贝格求积
阅读量:4355 次
发布时间:2019-06-07

本文共 1228 字,大约阅读时间需要 4 分钟。

#include <stdio.h>

#include <stdlib.h>
#include<conio.h>
#include<math.h>
#include<string.h>

double f(double x)

{
return (4*x*x/(1+x*x));
}

double Romberg(double top,double bottom,double precision)

{
int k=1;
double S,x,T1,T2,S1,S2,C1,C2,R1,R2,h=bottom-top;

/*

转载请注明出处:去转盘网www.quzhuanpan.com
*/

//S梯形公式,T梯型变步长,S梯形加速,C幸普森加速,R龙贝格求积

T1=h*(f(top)+f(bottom))/2;//梯形公式
while(1)
{
S=0;
x=top+h/2;
do
{
S+=f(x);
x+=h;

}while(x<bottom);

T2=(T1+h*S)/2.0;
if(fabs(T2-T1)<precision)
{
return T2;
}
S2=T2+(T2-T1)/3;//梯形加速
if(k==1)
{
T1=T2;
S1=S2;//几下原来的S2
h/=2;
k+=1;
continue;
}
C2=S2+(S2-S1)/15;//新的S2减原来的S2,即使S1,幸普森加速
if(k==2)
{
C1=C2;
T1=T2;
S1=S2;
h/=2;
k+=1;
continue;
}
R2=C2+(C2-C1)/63.0;
if(k==3)
{
R1=R2;
C1=C2;
T1=T2;
S1=S2;
h/=2;
k+=1;
continue;
}
if(fabs(S2-S1)<precision)
{
return S2;
}
C1=C2;
T1=T2;
S1=S2;
h/=2;
k+=1;
if(fabs(R2-R1)<precision);
{
return R2;
}
}
}

int main()

{
double top,bottom,precision,S;
printf("Pletopse input the begin: ");
scanf("%lf",&top);
printf("Pletopse input the end: ");
scanf("%lf",&bottom);
printf("Pletopse input the precision:");
scanf("%lf",&precision);
S=Romberg(top,bottom,precision);
printf("The result is:%lf",S);
getch();
return 0;
}

转载于:https://www.cnblogs.com/worm0707/p/5144881.html

你可能感兴趣的文章
[深度思考]·为什么CNN是同步(并行)而RNN是异步(串行)的呢?
查看>>
一键GHOST使用图文教程
查看>>
GNUPlot绘制曲线
查看>>
springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定
查看>>
Maven 入门
查看>>
20171107_Python学习四周二次课
查看>>
Orchard源码分析(4.1):Orchard.Environment.CollectionOrderModule类
查看>>
leetcode-109-有序链表转二叉搜索树
查看>>
WebView与 JS 交互方式
查看>>
中小公司统一用户认证方案
查看>>
【SDUT 3038】迷之博弈
查看>>
2014阿里实习生面试题——mysql如何实现的索引
查看>>
Android中ExpandableListView控件基本使用
查看>>
ASP.NET MVC Model绑定(二)
查看>>
一步一步写算法(之hash表)
查看>>
漫谈并发编程(一) - 并发简单介绍
查看>>
JDBC连接MySQL数据库及演示样例
查看>>
System.currentTimeMillis();
查看>>
javascript中使用Map
查看>>
C# DataTable的詳細使用方法
查看>>