{ "cells": [ { "cell_type": "markdown", "id": "4627e55d", "metadata": {}, "source": [ "# mathmoreIntegrationMultidim\n", "Example on the usage of the multidimensional integration algorithm of MathMore.\n", "\n", "Please refer to the web documentation for further details: \n", " https://root.cern/manual/math/#numerical-integration\n", "To execute the macro type the following:\n", "\n", "```cpp\n", "root[0] .x mathmoreIntegrationMultidim.C\n", "```\n", "\n", "This tutorial requires having libMathMore built with ROOT.\n", "\n", "To build mathmore you need to have a version of GSL >= 1.8 installed in your system\n", "The ROOT configure will automatically find GSL if the script gsl-config (from GSL) is in your PATH,.\n", "otherwise you need to configure root with the options --gsl-incdir and --gsl-libdir.\n", "\n", "\n", "\n", "\n", "**Author:** A. Tolosa-Delgado \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:25 PM." ] }, { "cell_type": "markdown", "id": "49a07916", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 1, "id": "2635b239", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:00.303560Z", "iopub.status.busy": "2026-05-19T20:26:00.303452Z", "iopub.status.idle": "2026-05-19T20:26:00.306597Z", "shell.execute_reply": "2026-05-19T20:26:00.306136Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "\n", "double f2(const double * x) {\n", " return x[0] + x[1];\n", "}" ] }, { "cell_type": "code", "execution_count": 2, "id": "fd3f6ee6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:00.307776Z", "iopub.status.busy": "2026-05-19T20:26:00.307662Z", "iopub.status.idle": "2026-05-19T20:26:00.776469Z", "shell.execute_reply": "2026-05-19T20:26:00.775871Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "integral result is 1\n", "integral result is 0.999998\n", "integral result is 0.999738\n", "integral result is 0.999881\n" ] } ], "source": [ "const double RESULT = 1.0;\n", "const double ERRORLIMIT = 1E-3;\n", "int status = 0;\n", "\n", "ROOT::Math::Functor wf(&f2,2);\n", "double a[2] = {0,0};\n", "double b[2] = {1,1};\n", "\n", "ROOT::Math::IntegratorMultiDim ig(ROOT::Math::IntegrationMultiDim::kADAPTIVE);\n", "ig.SetFunction(wf);\n", "double val = ig.Integral(a,b);\n", "std::cout << \"integral result is \" << val << std::endl;\n", "status += std::fabs(val-RESULT) > ERRORLIMIT;\n", "\n", "ROOT::Math::IntegratorMultiDim ig2(ROOT::Math::IntegrationMultiDim::kVEGAS);\n", "ig2.SetFunction(wf);\n", "val = ig2.Integral(a,b);\n", "std::cout << \"integral result is \" << val << std::endl;\n", "status += std::fabs(val-RESULT) > ERRORLIMIT;\n", "\n", "ROOT::Math::IntegratorMultiDim ig3(wf,ROOT::Math::IntegrationMultiDim::kPLAIN);\n", "val = ig3.Integral(a,b);\n", "std::cout << \"integral result is \" << val << std::endl;\n", "status += std::fabs(val-RESULT) > ERRORLIMIT;\n", "\n", "ROOT::Math::IntegratorMultiDim ig4(wf,ROOT::Math::IntegrationMultiDim::kMISER);\n", "val = ig4.Integral(a,b);\n", "std::cout << \"integral result is \" << val << std::endl;\n", "status += std::fabs(val-RESULT) > ERRORLIMIT;\n", "\n", "return status;" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }