Title:
solution:
x 2 a 2 + y 2 b 2 = 1 \ frac {x ^ 2} {a ^ 2} + \ frac {y ^ 2} {b ^ 2} = 1 a2x2+b2and2=1
b 2 x 2 + a 2 y 2 = a 2 b 2 b ^ 2x ^ 2 + a ^ 2y ^ 2 = a ^ 2b ^ 2 b2 x2+a2 y2=a2 b2
y 2 = a 2 b 2 - b 2 x 2 a 2 y ^ 2 = \ frac {a ^ 2b ^ 2-b ^ 2x ^ 2} {a ^ 2} and2=a2a2 b2−b2 x2
y = a 2 b 2 − b 2 x 2 a 2 y=\sqrt{\frac{a^2b^2-b^2x^2}{a^2}} and=a2a2 b2−b2 x2
y = a 2 b 2 − b 2 x 2 a y=\frac{\sqrt{a^2b^2-b^2x^2}}{a} and=aa2 b2−b2 x2
y = b ∗ a 2 − x 2 a y=\frac{b*\sqrt{a^2-x^2}}{a} and=ab∗a2−x2
The answer is the integral of y on [l, r ]∗ 2, and the answer is the integral of y on [l,r]*2, A case is y in [ L ,R & lt ] On the plot points∗2,
Multiply 2 because there are two upper and lower parts. Multiply 2 because there are two upper and lower parts. By 2 is because as there are on the lower two portion points .
Use Adaptive Simpson to calculate the integral value. Use Adaptive Simpson to calculate the integral value. With self adapted to be oct- Pu Sen to count calculated plot points of value .
code:
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-6;
double a,b,l,r;
double f(double x){
//被积函数求值
return b*sqrt(a*a-x*x)/a;
}
double simpson(double l,double r){
double mid=(l+r)/2;
return (r-l)*(f(l)+4*f(mid)+f(r))/6;
}
double ask(double l,double r,double eps,double ans){
double mid=(l+r)/2;
double fl=simpson(l,mid),fr=simpson(mid,r);
if(fabs(fl+fr-ans)<=15*eps)return fl+fr+(fl+fr-ans)/15;
return ask(l,mid,eps/2,fl)+ask(mid,r,eps/2,fr);
}
signed main(){
int T;scanf("%d",&T);
while(T--){
scanf("%lf%lf%lf%lf",&a,&b,&l,&r);
double ans=2*ask(l,r,eps,simpson(l,r));
printf("%.3f\n",ans);
}
return 0;
}