📄 repeat_t.cpp
字号:
/////////////////////////////////////////////////////////////////
// §3 数值积分
//
// 程序3.1 — 复化T型公式
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include "expressi.cpp"
// 积分区间[a,b], 被积函数 f(x) = FxString, 等份数 n
float RepeatT( char FxString[], float a, float b, int n )
{
int i;
float h, Value;
if( n <= 0) return 0;
h = ( b - a ) / n;
if( CreateFx( FxString ) ) return 0; // 建立f(x)
Value = 0;
for( i = 1; i < n; ++i )
{
Value += f( a + i * h );
}
return( ( f(a) + f(b) + 2 * Value ) * h / 2 );
}
void main()
{
float i1,a,b;
int n;
char FxString[200];
printf( "\nInput function, a, b, n: " );
scanf( "%s %f %f %d", FxString, &a, &b, &n );
i1 = RepeatT(FxString,a,b,n);
printf( "\n%f", i1 );
getch( );
}
/*
运行实例:
Input function,a,b,n: 1/(1+x) 0 1 10
0.693771
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -