C语言实现龙贝格求积
来源:互联网 发布:北航网络继续教育学院 编辑:程序博客网 时间:2024/06/01 08:21
#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;
}
#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;
}
0 0
- C语言实现龙贝格求积
- 链栈 C语言实现
- 地球 c语言实现
- C语言实现堆栈
- c语言实现计算器
- TrimLeft C语言实现
- C语言实现有限状态机
- 迪杰斯特拉 C语言实现
- C语言实现FIR
- C语言实现有限状态机
- C语言实现双链表
- C语言实现析构器
- C语言实现:万年历
- C语言实现有限状态机
- 二叉排序树 C语言实现
- C语言实现库函数
- c语言实现memcpy
- 基数排序C语言实现
- 将 CONNECT BY 移植到 DB2
- vsftpd 500
- 关于收集
- MVP模式在android中的流程详解
- 几秒前,几分钟前,几小时前,几天前,几月前,几年前的java实现
- C语言实现龙贝格求积
- Android中的IPC机制(3)-Messenger
- 160120ViewController生命周期详解
- jsp标签库(jstl)
- Masonry介绍与使用实践:快速上手Autolayout
- <设计模式>系列汇总 By python and C++
- Ubuntu 下安装 maven
- java中几个时间的区别(java.sql.date,java.sql.time,java.sql.Timestamp)
- 数据库事务解析及事务四个特性