T554476 mh逆积分
题目背景
在一个风雨交加的白天,小左突然感受到了微分方程的力量,这道微分方程是:
$${\ddot\theta(t)=-\frac{g}{L}\sin(\theta(t))}$$
按照传统的方法——《[那首疯狂的歌](https://music.163.com/#/song?id=386830)》,这个方程是这么解的:
首先,写出:
$${p=\frac{\mathrm{d}\theta}{\mathrm{d}t}}$$
得到:
$${\ddot\theta=\frac{\mathrm{d}p}{\mathrm{d}t}=\frac{\mathrm{d}p}{\mathrm{d}\theta}\cdot\frac{\mathrm{d}\theta}{\mathrm{d}t}=p\frac{\mathrm{d}p}{\mathrm{d}\theta}}$$
所以,原方程变为:
$${p\frac{\mathrm{d}p}{\mathrm{d}\theta}=-\frac{g}{L}\sin(\theta)}$$
去分母,得:
$${Lp\mathrm{d}p=-\sin(\theta)\mathrm{d}\theta}$$
$${L\int p\mathrm{d}p=g\int \sin(\theta)\mathrm{d}\theta}$$
$${\frac{L}{2}p^2=g\cos(\theta)+A}$$
$${\left(\frac{\mathrm{d}\theta}{\mathrm{d}t}\right)^2=\frac{2g}{L}\cos(\theta)+A}$$
$${\frac{\mathrm{d}\theta}{\mathrm{d}t}=\pm\sqrt{\frac{2g}{L}\cos(\theta)+A}}$$
$${\pm\frac{\mathrm{d}\theta}{\sqrt{\frac{2g}{L}\cos(\theta)+A}}=\mathrm{d}t}$$
$${ \pm\int \frac{\mathrm{d}\theta}{\sqrt{\frac{2g}{L}\cos(\theta)+A}}=t+B}$$
最后一个积分的结果小左求不出来,因此他求助小右,但是小右想让他锻炼锻炼,所以决定让小左自行用数值方法。
题目描述
小左是这么思考的:如果是求
$${t=\int \frac{\mathrm{d}\theta}{\sqrt{\frac{2g}{L}\cos(\theta)+A}}-B}$$
那倒好表示,但这里是求
$${\theta(t)}$$
我们需要求t的反函数,也就是说如果 $a$ 是某个值:
$${\theta^{-1}=\int_{a}^{\theta(t)}\frac{\mathrm{d}\theta}{\sqrt{\frac{2g}{L}\cos(\theta)+A}}}$$
我们给出定义:
$${(x=\mathrm{mh}(f,a,s)):=(\int_{a}^{x}f(t)\mathrm{d}t=s)\wedge\forall x_0(\int_{a}^{x_0}f(t)\mathrm{d}t=s\Rightarrow|x-a|\le|x_0-a|)}$$
$${\wedge\forall x_0(\int_{a}^{x_0}f(t)\mathrm{d}t=s\wedge|x-a|=|x_0-a|\Rightarrow x\ge x_0)}$$
你需要计算 $\mathrm{mh}(f,a,s)$ 的值,而且根据这个定义,
$$\theta(t)=\mathrm{mh}(f,a,t)\left|f(x)=\left(\frac{2g}{L}\cos(x)+A\right)^{-\frac{1}{2}}\right.$$
输入格式
首行输入一个 $$\text{opt}$$
---
**当 $$\text{opt}=0$$ 时:**
接下来的一行使用 LaTex 给出一个函数 $$f(x)$$ 的全微分方程,比如
```
f''=f'*f
```
或
```
{d^2f}/{dx^2}={df}/{dx}*f
```
代表方程 $$\displaystyle\frac{\mathrm{d}^2f}{\mathrm{d}x^2}=\frac{\mathrm{d}f}{\mathrm{d}x}\times f$$.
接下来的 $$(n+1)$$ 行会给出确定一个函数的初始条件:
```
2 //这个是n
f(0)=f_0
f'(0)=v_0
```
注意,这个条件给出的格式不唯一.
接下来的 $$(q+1)$$ 行给出 $$q$$ 个 $$x$$ 的值并查询这 $$q$$ 个 $$f(x)$$ 的值.
```
2 //这个是q
2*\pi
2*arctan(1/2)
```
本例中的 $$\displaystyle f(x)=\left(v_0-\frac{1}{2}f_0^2\right)\tan\left(\frac{x}{2}+\arctan\left(\frac{f_0}{v_0-\frac{1}{2}f_0^2}\right)\right)$$ 或者
$$\large f(x)=\frac{\left(v_0-\frac{1}{2}f_0^2\right)^2\tan\left(\frac{x}{2}\right)+v_0f_0-\frac{1}{2}f_0^3}{v_0-\frac{1}{2}f_0^2-f_0\tan\left(\frac{x}{2}\right)}$$
但是在 $$\mathrm{mh}$$ 情况下 $$f(x)$$ 又可以写作:
$$\large f(x)=\mathrm{mh}(g,f_0,x)\left|g(x)=\frac{2}{x^2+v_0-\frac{1}{2}f_0}\right.$$
总的来说,这个输入应该是:
```
0
f''=f'*f
2
f(0)=0
f'(0)=1
2
2*\pi
2*arctan(1/2)
```
---
**当 $$\text{opt}=1$$ 时:**
给出一个函数 $$f(x)$$ 和他的表达式,这可能包括[某个神秘题目](https://www.luogu.com.cn/problem/T535018)中提到的所有函数以及他们的 $$\sum$$,$$\int$$,$$\prod$$ 等,这中的单个项符合这道神秘题目的输入的格式,即可能存在的第二行:
```
f(x)=(sin(x)^2+cos(x)^2)*\int_x^\infty e^-t dt
```
即$$\displaystyle f(x)=\left(\sin^2x+\cos^2x\right)\times\int_x^\infty e^{-t}\mathrm{d}t$$
往下的 $$(q+1)$$ 行输入,格式为$$\displaystyle\mathrm{mh}(f,a,s)$$,即可能出现以下输入:
```
1
f(x)=(sin(x)^2+cos(x)^2)*\int_x^\infty e^-t dt
1 //q
mh(f,a,270)
```
输出格式
**当 $$\text{opt}=0$$ 时:**
对于每一个询问 $$x$$,每一行输出所求的 $$f(x)$$
共 $$q$$ 行
---
**当 $$\text{opt}=1$$ 时:**
对于每一个询问 $$\mathrm{mh}$$,每一行输出 $$\mathrm{mh}(f,a,s)$$ 的值
共 $$q$$ 行
---
输出误差小于 $$\displaystyle 10^{-9}$$
说明/提示
$$\text{opt}\in\{0,1\}$$
$$f\in C^{(\infty)}$$
题目保证微分方程有解析解