欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實(shí)現(xiàn)黎曼和求定積分

 更新時(shí)間:2020年02月27日 12:07:32   作者:liu_if_else  
這篇文章主要為大家詳細(xì)介紹了用C語言程序?qū)崿F(xiàn)黎曼和求定積分,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C語言程序?qū)崿F(xiàn)黎曼和求定積分,供大家參考,具體內(nèi)容如下

通過黎曼和解定積分既是把在xy平面中函數(shù)曲線與x軸區(qū)間區(qū)域劃分成多個(gè)矩形并求它們的面積之和,矩形數(shù)量越多,得出的面積越精確。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
 
int main(){ 
 float function1(float);        //函數(shù)f(x)1
 float function2(float);        //函數(shù)f(x)2
 float function3(float);        //函數(shù)f(x)3
 void integration(float f(float),float,float);  //求定積分方法,參數(shù)為,函數(shù)fx,區(qū)間[a,b]的兩個(gè)點(diǎn) 
 
 int result_a=integration(function1,1,0);   
 int result_b=integration(function2,1,-1); 
 int result_c=integration(function3,2,0);  
}
 
void integration(float f(float),float endPos,float startPos) //求定積分方法,參數(shù)為,函數(shù)fx,區(qū)間[a,b]的兩個(gè)點(diǎn) 
{ 
 float x;
 float totalArea=0; //totalArea,所有矩形的總面積 
 float n=1000;  //將函數(shù)曲線下方劃為n個(gè)矩形,n值越大,精確值越高 
 float width;   //單個(gè)矩形寬度 
 float area=0;  //單個(gè)矩形面積 
 width=(endPos-startPos)/n;  //求單個(gè)矩形寬度,既是函數(shù)總長度除以矩形數(shù)量 
 for(float i=1;i<=n;i++)   //計(jì)算每個(gè)矩形的面積 
 {  
 x=startPos+width*i;  //轉(zhuǎn)入到xy平面, 通過i的遞增,得出每個(gè)矩形底部x的值,以求矩形高度  
 area=f(x)*width;   //用x做實(shí)參調(diào)用函數(shù)進(jìn)一步求出y值,既矩形的高度,再用底乘高得出面積  
 totalArea=totalArea+area;   //各個(gè)矩形面積相加 
 } 
 printf("the value of function is %f",t2); 
}
 
float function1(float x){ //函數(shù)f(x)1
 float y; 
 y=sin(x); 
 return y;
}
 
float function2(float x){ //函數(shù)f(x)2
 float y; 
 y=cos(x); 
 return y;
}
float function3(float x){ //函數(shù)f(x)3
 float y; 
 y=exp(x); 
 return y;
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論