{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "1e600c87",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "9b76bf22",
            "cell_type": "markdown",
            "source": "Calculate\n\n$$ \\int^{1}_{-0.15} \\int^{0.8}_{0.13} \\int^{1}_{-1} \\int^{1}_{0} f(x_0, x_1, x_2, x_3) \\,dx_0 \\,dx_1 \\,dx_2 \\,dx_3 , $$\nwhere\n\n$$ f(x_0, x_1, x_2, x_3) = \\begin{cases} x_0^2+x_1 x_2-x_3^3+ \\sin{x_0}+1 & (x_0-0.2 x_3-0.5-0.25 x_1 > 0) \\\\ x_0^2+x_1 x_2-x_3^3+ \\sin{x_0}+0 & (x_0-0.2 x_3-0.5-0.25 x_1 \\leq 0) \\end{cases} . $$",
            "metadata": {}
        },
        {
            "id": "ca7262cc",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy import integrate\nfunc = lambda x0,x1,x2,x3 : x0**2 + x1*x2 - x3**3 + np.sin(x0) + (\n                                1 if (x0-.2*x3-.5-.25*x1>0) else 0)\ndef opts0(*args, **kwargs):\n    return {'points':[0.2*args[2] + 0.5 + 0.25*args[0]]}\nintegrate.nquad(func, [[0,1], [-1,1], [.13,.8], [-.15,1]],\n                opts=[opts0,{},{},{}], full_output=True)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(1.5267454070738633, 2.9437360001402324e-14, {'neval': 388962})"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "839959a2",
            "cell_type": "markdown",
            "source": "Calculate\n\n$$ \\int^{t_0+t_1+1}_{t_0+t_1-1} \\int^{x_2+t_0^2 t_1^3+1}_{x_2+t_0^2 t_1^3-1} \\int^{t_0 x_1+t_1 x_2+1}_{t_0 x_1+t_1 x_2-1} f(x_0,x_1, x_2,t_0,t_1) \\,dx_0 \\,dx_1 \\,dx_2, $$\nwhere\n\n$$ f(x_0, x_1, x_2, t_0, t_1) = \\begin{cases} x_0 x_2^2 + \\sin{x_1}+2 & (x_0+t_1 x_1-t_0 > 0) \\\\ x_0 x_2^2 +\\sin{x_1}+1 & (x_0+t_1 x_1-t_0 \\leq 0) \\end{cases} $$\nand $(t_0, t_1) = (0, 1)$ .\n",
            "metadata": {}
        },
        {
            "id": "3f601257",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "def func2(x0, x1, x2, t0, t1):\n    return x0*x2**2 + np.sin(x1) + 1 + (1 if x0+t1*x1-t0>0 else 0)\ndef lim0(x1, x2, t0, t1):\n    return [t0*x1 + t1*x2 - 1, t0*x1 + t1*x2 + 1]\ndef lim1(x2, t0, t1):\n    return [x2 + t0**2*t1**3 - 1, x2 + t0**2*t1**3 + 1]\ndef lim2(t0, t1):\n    return [t0 + t1 - 1, t0 + t1 + 1]\ndef opts0(x1, x2, t0, t1):\n    return {'points' : [t0 - t1*x1]}\ndef opts1(x2, t0, t1):\n    return {}\ndef opts2(t0, t1):\n    return {}\nintegrate.nquad(func2, [lim0, lim1, lim2], args=(0,1),\n                opts=[opts0, opts1, opts2])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(36.099919226771625, 1.8546948553373528e-07)"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}