Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
自适应梯形公式(变步长).cpp
Package: shuzhi_C++.rar [view]
Upload User: hks123456
Upload Date: 2014-01-27
Package Size: 18k
Code Size: 1k
Category:
Algorithm
Development Platform:
Visual C++
- #include<iostream.h>
- #include<math.h>
- int n;
- float f(float);
- void main()
- {
- float s;
- float AutoTrap(float (*)(float),float,float);
- s=AutoTrap(f,0.0,1.0);
- cout<<"T("<<n<<")="<<s<<endl;
- }
- float AutoTrap(float (*)(float),float a,float b)
- {
- int i;
- float x,s,h=b-a;
- float t1,t2=h/2.0*(f(a)+f(b));
- n=1;
- do{
- s=0.0;
- t1=t2;
- for(i=0;i<=n-1;i++)
- {
- x=a+i*h+h/2;
- s+=f(x);
- }
- t2=(t1+s*h)/2.0;
- n*=2;
- h/=2.0;
- }while( fabs(t2-t1)>1e-6);
- return t2;
- }
- float f(float x)
- {
- return 1/(1+x*x);
- }
- //用变步长梯形法计算积分积分只要将函数定义为
- /*float f(float x)
- {
- if(x==0)
- return 1;
- else
- return sin(x)/x;
- }*/