变步长梯形求积法

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
#define epsilon 0.00001
float f(float x){
 return(x/(4.0+x*x));
}
float computeT(float a,float b){
 float T=0,h=(b-a)/2;
 T=h*(f(a)+2*T+f(b))/2;
 return T;
}
int main(){
 int i;
 float a,b,T1,T2,S,x,h;
 printf("\n Input the begin:");
 scanf("%f",&a);
 printf("\n Input the end:");
 scanf("%f",&b);
 h=b-a;
 T1=computeT(a,b);
 while(1){
  S=0;
  x=a+h/2;
  do
  {
   S+=f(x);
   x+=h;
  }while(x<b);
  T2=(T1+h*S)/2;
  if(fabs(T2-T1)>=epsilon){
   T1=T2;
   h=h/2;
   continue;
  }
  else
   break;
 }
 printf("solve is:%f",T2);
 getch();
 return S;
}

时间: 2024-07-29 16:44:36

变步长梯形求积法的相关文章

积分:变步长梯形法

#include <stdio.h> #include <math.h> #include <iomanip> #define e 2.7182818 double f(double x) { return pow(e,-x*x); } double Calc(double a,double b,double esp) { int done(0); int n=1; double h,Tn,T2n,k,temp,x; h=b-a; Tn=h*(f(a)+f(b))/2.

复化梯形求积法

#include<stdio.h>#include<string.h>#include<math.h>#include<conio.h>#include<stdlib.h>#define epsilon 0.00001float f(float x){ return (1.0/(1.0+x*x));}float computeT(float a,float b){ float T=0,h=(b-a)/2; T=h*(f(a)+2*T+f(b))/

数值积分——复合梯形求积公式

这段代码实现的是最一般的数值积分法——梯形求积法,积分值的准确依赖于所取精度大小 1.代码 %%复合梯形求积公式 %%Y是数值(attribute=0)或具体表达式(attribute=1),interval是求积区间,n是精度(如果是数值,则为数值长度-1) function CTQF = Compound_trapezoid_quadrature_formula(Y,interval,n,attribute) a = interval(1);b = interval(2); h = (b-a

实验三 数值积分(android)

实验二博客地址:http://blog.csdn.net/double2hao/article/details/51217356 实验一博客地址:http://blog.csdn.net/double2hao/article/details/51152843 一.实验内容 分别写出变步长梯形法和romberge法计算定积分的算法,编写程序上机调试出结果,要求所编程序适用于任何类型的定积分,即能解决这一类问题,而不是某一个问题. 试验中以下列数据验证程序的正确性. 求  (sinx)/x的积分,积

微积分知识补充——兼怀102

原文 看到这题目是不是各种奇葩吖…… 其实我真的只是想写写微积分,然后再(shunbian)怀念一下高一上学期的生活. 想我5个月前,刚刚进入JSZX时,还只是个稍微知道点极限,导数,积分定义的大煞X,经过一个学期勤勤恳恳的学习,虽然还是什么都不懂,但似乎并没有什么关系. 文末再怀念吧……先补充一些东西. 之前的日志里,都仅仅是说当自变量趋近于什么什么值的时候函数值为其极限,然而真正的极限是:对于任意a>0,存在b>0使得当x在x0的去心领域(x0,b)内时,有|f(x)-p|<a,则称

梯形成形算法的FPGA实现

续上~~~梯形成形算法,上贴是原理仿真与软件实现,这一贴是硬件实现. 将系统函数分解为4个子模块: H(z)=H1(z)*H2(z)*H3(z)*H4(z) 式中: H1(z)=(1-qz-1)/(1-z-1); H2(z)=1-z-k; H3(z)=1-z-1; H4(z)=(1/ta)*(z-1)/(1-z-1) 4个子模块的级联存在顺序问题,要避免具有峰值增益的子系统发生溢出或将量化噪声扩大.所以把H1置于第一级; H4为积分单元,为了避免产生溢出,将其置于最后一级; H2.H3置于中间,

1104: 零起点学算法11——求梯形面积

1104: 零起点学算法11--求梯形面积 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 6473  Accepted: 1875[Submit][Status][Web Board] Description 水题 Input 输入3个浮点数,分别表示上底.下底和高,中间用逗号隔开(题目包含多组数据) Output 输出梯形的面积,保留2位小数 Sample Input 2,4,5 Sample

平行四边形、梯形

平行四边形: width: height: transform:skew(度数 deg) background: color 梯形: border-bottom:100px solid red border-left:50px solid transparent border-right:50px solid transparent height:0 weight:100px

css 梯形标签页

html 代码 略 css : nav > a{ position: relative; display: inline_block; padding: .3em 1em 0; } nav > a { content: ''; position: absolute; top: 0; right: 0; bottom:0; left: 0; z-index: -1; background: #ccc; background-image:linear-gradint( hsla(0,0%,100%