c语言积分调节函数 c语言实现积分运算

用C语言编写一个求定积分的程序这是辛普森积分法 。
给你写c语言积分调节函数了fun_1( )c语言积分调节函数,fun_2()c语言积分调节函数,请自己添加另外几个被积函数 。
调用方法t=fsimp(a,b,eps,fun_i);
a,b --上下限c语言积分调节函数,eps -- 迭代精度要求 。
#includestdio.h
#includestdlib.h
#include math.h
double fun_1(double x)
{
return 1.0x ;
}
double fun_2(double x)
{
return 2.0 * x3.0 ;
}
double fsimp(double a,double b,double eps, double (*P)(double))
{
int n,k;
double h,t1,t2,s1,s2,ep,p,x;
n=1; h=b-a;
t1=h*(P(a) P(b))/2.0;
s1=t1;
ep=eps 1.0;
while (ep=eps)
{
p=0.0;
for (k=0;k=n-1;k)
{
x=a (k 0.5)*h;
p=p P(x);
}
t2=(t1 h*p)/2.0;
s2=(4.0*t2-t1)/3.0;
ep=fabs(s2-s1);
t1=t2; s1=s2; n=n n; h=h/2.0;
}
return(s2);
}
void main()
{
double a,b,eps,t;
a=0.0; b=3.141592653589793238; eps=0.0000001;
// a definite integral by Simpson Method.
t=fsimp(a,b,eps,fun_1);
printf("%g\n",t);
t=fsimp(a,b,eps,fun_2);
printf("%g\n",t);
// ...
printf("\n Press any key to quit...");
getch();
}
c语言 求定积分的通用函数对于一重定积分来说其求解可以使用梯形法进行求解c语言积分调节函数,计算公式如下所示:
其中c语言积分调节函数,f(x)为被积函数,为横坐标的两点间的间隔,越?。蚣扑愠龅慕峁骄?。
对于求解此类问题可以使用C语言中的回调函数编写通用的计算函数,代码如下:
#include stdio.h
#include stdlib.h
#includemath.h
//功能:返回f(x)在积分区间[a,b]的值
//参数:FunCallBack 指向用于计算f(x)的函数
//a积分区间的起始值
//b积分区间的结束值
//dx 横坐标的间隔数 , 越小计算结果越准确
double Calculate(double (*FunCallBack)(double x),
double a,double b,double dx)
{
double doui;
double total = 0;//保存最后的计算结果
for (doui = a; doui = b; doui= dx)
{
total= FunCallBack(doui)*dx;
}
return total;
}
double f2(double x)
{
return x*x;
}
double f(double x)
{
return x;
}
double f3(double x)
{
【c语言积分调节函数 c语言实现积分运算】return x*x*x ;
}
int main()
{
double total;
total = (Calculate(f, 2, 3, 0.000001));
printf("total = %lf\n", total);
total = (Calculate(f2, 2, 3, 0.000001));
printf("total = %lf\n", total);
total = (Calculate(f3, 2, 3, 0.000001));
printf("total = %lf\n", total);
return 0 ;
}
其中,函数f,f2,f3为自行编写的关于x的被积函数 。
运行结果:
total = 2.500000
total = 6.333331
total = 16.249991
怎样编写c语言积分函数用梯形法求函数f(x#include
float f(float x)
{
return x*x 2*x 1;
}
void main()
{
float a,b,len,F=0;//
int n,i;
printf("Please input a,b: ");
scanf("%f%f",a,b);
printf("Please input n: ");
scanf("%d",n);
len=(a b)/n;//区间度
for(i=0;in;i)
{
F =len*f(a);
a =len;
}
printf("%f\n",F);
}
结例:
Please input a,b: 0 10.0
Please input n: 100
437.349792
怎样编写c语言积分函数积分分为两种 , 数值积分,公式积分 。
公式积分:部分函数可以直接用公式求得其不定积分函数 。C语言中可以直接用积分公式写出其积分函数 。
数值积分:按照积分的定义,设置积分范围的步长,用梯形面积累加求得其积分 。
以【f(x)=x*sin(x) 从1到2的积分】为例:
#include math.h
#include stdio.h
double integral(double(*fun)(double x),double a,double b,int,n){
double s,h,y;
int i;
s=(fun(a) fun(b))/2;
h=(b-a)/n; /*积分步长*/
for(i=1;in;i)
s=s fun(a i*h);
y=s*h;
return y;/*返回积分值*/
}
double f(double x){
return(x*sinx)/*修改此处可以改变被积函数*/
}
int main(){
double y;
y=integral(f,1.0,2.0,150);/*修改此处可以改变积分上下限和步数,步长=(上限-下限)/步数*/
printf("y=%f\n",y);
return 0;
}
高手啊!给我用C语言编个积分函数!函数我在下面给出了 。double thelta = 1e-7;
double a = 0,b = B;
double result = 0;
for(double t = a;tb;t =thelta)
{
result =t*M(t);
}
M那个函数你自己编个函数就行了;
用C语言编写的PI调节器函数,采用位置式算法,求大神指教typedef struct{
float limit;//输出限幅
float target;//设置量
float feedback; //实测量
float Kp;//比例系数
float Ki;//积分系数
float Kd;//微分系数
float eSum;//误差积分
float e0;//当前误差
float e1;//上一次误差
}PIDType;
#define max(a, b)(ab? a:b)
#define min(a, b)(ab? a:b)
#define range(x, a, b)(min(max(x, a), b))
float pid_pos_update(PIDType *p)
{
float pe, ie, de;
float out=0;
//计算当前误差
p-e0 = p-target - p-feedback;
//误差积分
p-eSum= p-e0;
//误差微分
de = p-e0 - p-e1;
pe = p-e0;
ie = p-eSum;
p-e1 = p-e0;
//数据增量
out = pe*(p-Kp)ie*(p-Ki)de*(p-Kd);
//输出限幅
out = range(out, -p-limit, p-limit);
return out;
}
关于c语言积分调节函数和c语言实现积分运算的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读