標(biāo)題:
c語言實(shí)現(xiàn)積分環(huán)節(jié)
[打印本頁(yè)]
作者:
XI666xi
時(shí)間:
2018-5-6 12:40
標(biāo)題:
c語言實(shí)現(xiàn)積分環(huán)節(jié)
以c為例:求f(x)=xsinx從1到2的積分
#include <math.h>
float integral(float(*fun)(float x),float a,float b,int,n)
{float s,h,y;
int i;
s=(fun(a)+fun(b))/2;
h=(b-a)/n; /*積分步長(zhǎng)*/
for(i=1;i<n;i++)
s=s+fun(a+i*h);
y=s*h;
return y;/*返回積分值*/
}
float f(float x)
{return(x*sinx) /*修改此處可以改變被積函數(shù)*/
}
main()
{float y;
y=integral(f,1.0,2.0,150);/*修改此處可以改變積分上下限和步長(zhǎng)*/
printf("y=%f\n",y);
}
作者:
XI666xi
時(shí)間:
2018-5-6 12:41
各位大神幫忙,看看
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1