Skip to content

Instantly share code, notes, and snippets.

@pomo-mondreganto
Last active March 3, 2019 10:58
Show Gist options
  • Save pomo-mondreganto/a440a731d9b95b8a48b1c3d23cdb144e to your computer and use it in GitHub Desktop.
Save pomo-mondreganto/a440a731d9b95b8a48b1c3d23cdb144e to your computer and use it in GitHub Desktop.
БДЗ 2, задача 14
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$f(x) = \\sin \\frac{\\pi}{2} x^2 \\quad [a, b] = [0, \\frac{3}{2}]$\n",
"\n",
"$f'(x) = \\pi x \\cos \\frac{\\pi}{2} x^2$\n",
"\n",
"$f'(x) = 0$\n",
"\n",
"$x = 0, x^2 = 2k + 1, k \\in \\mathbb{Z}$\n",
"\n",
"На $[0, \\frac{3}{2}]$ $x = 0, 1$\n",
"\n",
"На $(0, 1)$ $f'(x) > 0 \\rightarrow f(x) \\uparrow$ на $[0, 1]$\n",
"\n",
"На $(1, \\frac{3}{2})$ $f'(x) < 0 \\rightarrow f(x) \\downarrow$ на $[1, \\frac{3}{2}]$\n",
"\n",
"Тогда если $\\tau_n: x_0 = 0, x_i = \\frac{3}{2n} i$, то:\n",
"\n",
"если $x_i < x_{i + 1} \\leq 1$, то $\\sup_{[x_i, x_{i + 1}]}(f(x)) = f(x_{i + 1}), \\quad \\inf_{[x_i, x_{i + 1}]}(f(x)) = f(x_i)$\n",
"\n",
"если $1 \\leq x_i < x_{i + 1}$, то $\\sup_{[x_i, x_{i + 1}]}(f(x)) = f(x_{i}), \\quad \\inf_{[x_i, x_{i + 1}]}(f(x)) = f(x_{i + 1})$\n",
"\n",
"если $x_i < 1 < x_{i + 1}$, то $\\sup_{[x_i, x_{i + 1}]}(f(x)) = f(1), \\quad \\inf_{[x_i, x_{i + 1}]}(f(x)) = \\min(f(x_i), f(x_{i + 1}))$\n",
"\n",
"$\\overline S_{\\tau_n} = \\sum_{i = 0}^{n - 1} \\sup_{[x_i, x_{i + 1}]}(f(x)) \\frac{3}{2n}$\n",
"\n",
"$\\underline S_{\\tau_n} = \\sum_{i = 0}^{n - 1} \\inf_{[x_i, x_{i + 1}]}(f(x)) \\frac{3}{2n}$"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def f(x):\n",
" return np.sin(np.pi * x * x / 2.)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def get(n):\n",
" upper = 0.\n",
" lower = 0.\n",
" d = 3. / (2. * n)\n",
" \n",
" for i in range(n):\n",
" x_i = d * i\n",
" x_ii = d * (i + 1)\n",
" if x_i < x_ii <= 1:\n",
" sup = f(x_ii)\n",
" inf = f(x_i)\n",
" elif 1 <= x_i < x_ii:\n",
" sup = f(x_i)\n",
" inf = f(x_ii)\n",
" else:\n",
" sup = f(1)\n",
" inf = min(f(x_i), f(x_ii))\n",
" upper += sup * d\n",
" lower += inf * d\n",
" return lower, upper"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>lower</th>\n",
" <th>upper</th>\n",
" <th>delta</th>\n",
" </tr>\n",
" <tr>\n",
" <th>n</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>0.512500</td>\n",
" <td>0.867962</td>\n",
" <td>0.355462</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100</th>\n",
" <td>0.679555</td>\n",
" <td>0.715293</td>\n",
" <td>0.035738</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000</th>\n",
" <td>0.695717</td>\n",
" <td>0.699291</td>\n",
" <td>0.003574</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10000</th>\n",
" <td>0.697326</td>\n",
" <td>0.697684</td>\n",
" <td>0.000357</td>\n",
" </tr>\n",
" <tr>\n",
" <th>100000</th>\n",
" <td>0.697487</td>\n",
" <td>0.697523</td>\n",
" <td>0.000036</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" lower upper delta\n",
"n \n",
"10 0.512500 0.867962 0.355462\n",
"100 0.679555 0.715293 0.035738\n",
"1000 0.695717 0.699291 0.003574\n",
"10000 0.697326 0.697684 0.000357\n",
"100000 0.697487 0.697523 0.000036"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"interesting = [10, 100, 1000, 10000, 100000]\n",
"\n",
"results = []\n",
"\n",
"for n in interesting:\n",
" lower, upper = get(n)\n",
" results.append([lower, upper, upper - lower])\n",
"\n",
"df = pd.DataFrame(index=interesting, columns=['lower', 'upper', 'delta'], data=results)\n",
"df.index.name = 'n'\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$\\overline S_{\\tau_n} - \\underline S_{\\tau_n} < 1\\mathrm{e}{-4}$ для $n = 100000$\n",
"\n",
"Значение интеграла: $0.697487$"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.7",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment