어떻게 직사각형 법(사다리꼴 법)으로 포 인 트 를 구 합 니까?
4935 단어 직사각형 법사다리꼴 법적분 을 정 하 다
사 고 는 적분 구간 을 n 등분 으로 나 눈 다음 에 이 n 등분 을 사각형(또는 사다리꼴)으로 본 다음 에 모든 사각형(또는 사다리꼴)의 면적 을 구 하 는 것 이다.

간단 한 예:함수 X^2 의 포인트 구하 기
직사각형 법:
#include<iostream>
#include<math.h>
using namespace std;
int main(){
float fun(float x);
float a,b;
cout<<" X^2 a b:";
cin>>a>>b;
int n=50;// 50
float h=(b-a)/n;//h
float s=0;//s
float i=0;
for(i=a;i<b;i+=h){
s=s+fun(i)*h;
}
cout<<"
:"<<s<<endl;
cout<<endl;
}
float fun(float x){
return pow(x,2);
}

#include<iostream>
#include<math.h>
using namespace std;
int main(){
float fun(float x);
float a,b;
cout<<" X^2 a b:";
cin>>a>>b;
int n=50;// 50
float h=(b-a)/n;//h
float s=0;//s
float i=0;
for(i=a;i<b;i+=h){
s=s+((fun(i)+fun(i+h))*h)/2;
}
cout<<"
:"<<s<<endl;
cout<<endl;
}
float fun(float x){
return pow(x,2);
}

직사각형 법:
#include<iostream>
#include<math.h>
using namespace std;
int main(){
float fsin( float x);
float fcos( float x);
float fe( float x);
float fpf(float x);
float fun(float a,float b, int n,float (*p)(float x));
float a[4],b[4],r[4];
cout<<" a b:";
cin>>a[0]>>b[0];
r[0]=fun(a[0],b[0],50,fsin);
cout<<"
:"<<r[0]<<endl;
cout<<"
a b:";
cin>>a[1]>>b[1];
r[1]=fun(a[1],b[1],50,fcos);
cout<<"
:"<<r[1]<<endl;
cout<<"
e a b:";
cin>>a[2]>>b[2];
r[2]=fun(a[2],b[2],50,fe);
cout<<"
:"<<r[2]<<endl;
cout<<"
X^2 a b:";
cin>>a[3]>>b[3];
r[3]=fun(a[3],b[3],50,fpf);
cout<<"
:"<<r[3]<<endl;
cout<<endl;
return 0;
}
float fsin(float x){
return sin(x);
}
float fcos(float x){
return cos(x);
}
float fe(float x){
return exp(x);
}
float fpf(float x){
return pow(x,2);
}
float fun(float a,float b,int n,float (*p)(float x)){
float i;
float h=(b-a)/n;
float s=0;
for(i=a;i<b;i+=h){
s=s+p(i)*h;//
}
return s;
}

#include<iostream>
#include<math.h>
using namespace std;
int main(){
float fsin( float x);
float fcos( float x);
float fe( float x);
float fpf(float x);
float fun(float a,float b, int n,float (*p)(float x));
float a[4],b[4],r[4];
cout<<" a b:";
cin>>a[0]>>b[0];
r[0]=fun(a[0],b[0],50,fsin);
cout<<"
:"<<r[0]<<endl;
cout<<"
a b:";
cin>>a[1]>>b[1];
r[1]=fun(a[1],b[1],50,fcos);
cout<<"
:"<<r[1]<<endl;
cout<<"
e a b:";
cin>>a[2]>>b[2];
r[2]=fun(a[2],b[2],50,fe);
cout<<"
:"<<r[2]<<endl;
cout<<"
X^2 a b:";
cin>>a[3]>>b[3];
r[3]=fun(a[3],b[3],50,fpf);
cout<<"
:"<<r[3]<<endl;
cout<<endl;
return 0;
}
float fsin(float x){
return sin(x);
}
float fcos(float x){
return cos(x);
}
float fe(float x){
return exp(x);
}
float fpf(float x){
return pow(x,2);
}
float fun(float a,float b,int n,float (*p)(float x)){
float i;
float h=(b-a)/n;
float s=0;
for(i=a;i<b;i+=h){
s=s+((p(i)+p(i+h))*h)/2;//
}
return s;
}
