|
![]() | 作者: make920 [make920]
![]() |
登录 |
采用三种积分方式,利用VC++程序设计语言实现下列图形的积分。三种方法为: 1.变步长梯形积分。2.变步长矩形积分。3.变步长抛物线积分。 其图如下: ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() [此贴被 286(unique) 在 06月07日09时28分 编辑过] |
地主 发表时间: 04-06-05 12:38 |
![]() | 回复: tabris17 [tabris17] ![]() |
登录 |
数值计算啊 以前学过 用matlab也写过程序 现在都忘了 |
B1层 发表时间: 04-06-05 17:29 |
![]() | 回复: make920 [make920] ![]() |
登录 |
不管怎么样还是谢谢你啊!!我只能继续求助啊! [/IMG]http://www.20cn.net/cgi-bin/club/showpic.pl?u=make920&f=laug046.jpg[/IMG] ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
B2层 发表时间: 04-06-05 19:09 |
![]() | 回复: make920 [make920] ![]() |
登录 |
这是我找到的一个变步长为梯形积分! //Begin of file Trapzint.h //文件一,类声明 #include<iostream.h> #include<math.h> class F //抽象类F的声明 { public: virtual double operator()(double x) const=0; //纯虚函数重载运算符() }; class Fun:public F //公有派生类Fun声明 { public: double operator()(double x) const //虚函数的内联实现 { return log(1.0+x)/(1.0+x*x); // 被积函数 } }; class Integ //抽象Integ声明 { public: virtual double operator()(double a,double b,double eps) const=0; }; class Trapz:public Integ //公有派生类Trapz声明 { public: Trapz(const F&pf):f(pf){} //构造函数 double operator()(double a,double b,double eps) const; private: const F&f; //私有成员,F类对象的指针 }; //End of file Trapzint.h //Begin of file Trapzint.cpp //文件二,类实现 #include"Trapzint.h" //包含类的声明头文件 double Trapz:: operator()(double a,double b,double eps) const { //积分运算过程,重载运算符"()" int done(0); //是Trapz 类的虚函数成员 int n; double h,Tn,T2n; n=1; h=b-a; Tn=h*(f(a)+f(b))/2.0; //计算n=1时的积分值 while( ! done) { double temp(0.0); for (int k=0;k<n;k++) { double x=a+(k+0.5)*h; temp+=f(x); } T2n=(Tn+h*temp)/2.0; //变步长为梯形法计算 if (fabs(T2n-Tn)<eps)done=1; //判断积分误差 else //进行下一步计算 { Tn=T2n; n*=2; h/=2; } } return T2n; } //End of file Trapzint.cpp //b8-6.cpp //文件三,主函数 #include"Trapzint.h" //类声明头文件 void main() //主函数 { Fun f1; Trapz trapz1(f1); //声明Fun类的对象 cout<<"TRAPZ Int:"<<setprecision(7)<<trapz1(0,2,1e-7)<<endl; //计算并输出积分结果 } 仅代表个人意见! 哪位高手能够算出抛物线的! |
B3层 发表时间: 04-06-10 09:53 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号