当前位置:网站首页>【模板】自适应辛普森积分
【模板】自适应辛普森积分
2022-07-01 23:55:00 【哈希表扁豆】
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
double a,b,c,d,L,R;
double f(double x)//原函数
{
return (c*x+d)/(a*x+b);
}
double simpson(double l,double r)//三点辛普森
{
double mid = (l+r)/2;
return (r-l)*(f(l)+f(r)+4*f(mid))/6;
}
double integral(double l,double r,double eps)//自适应辛普森
{
double mid = (l+r)/2;
double SL = simpson(l,mid),SR = simpson(mid,r),ST = simpson(l,r);
if(fabs(ST-SL-SR)<=(eps*15))
return SL+SR+(SL+SR-ST)/15;
else return integral(l,mid,eps/2)+integral(mid,r,eps/2);
}
int main()
{
cin>>a>>b>>c>>d>>L>>R;
printf("%.6lf",integral(L,R,1e-6));
return 0;
}
边栏推荐
猜你喜欢
PyCharm调用matplotlib绘图时图像弹出问题怎么解决
边缘计算概述
关联性——组内相关系数
Redis master-slave synchronization
门级建模—课后习题
[QT] QT cannot find a solution to the compiler using msvc2017
【必会】BM41 输出二叉树的右视图【中等+】
Selectively inhibiting learning bias for active sampling
Multi table operation - one to one, one to many and many to many
PyTorch学习记录
随机推荐
Timer和ScheduledThreadPoolExecutor的区别
JPA handwritten SQL, received with user-defined entity classes
vue 强制清理浏览器缓存
Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object
【.Net Core】程序相关各种全局文件
Operate database transactions with jpatractionmanager
Shell custom function
Key points and difficulties of the course "information content security" at Harbin Institute of Technology
【QT】Qt 使用MSVC2017找不到编译器的解决办法
const // It is a const object... class nullptr_ t
微信小程序缓存过期时间的相关设置(推荐)
门级建模—课后习题
Selectively inhibiting learning bias for active sampling
VIM color the catalogue
Li Kou today's question -241 Design priorities for operational expressions
Notblank and notempty
Resumption of attack and defense drill
13 MySQL-约束
The essence of software architecture
S32Kxxx bootloader之UDS bootloader