{ "cells": [ { "cell_type": "markdown", "id": "8d7afaa0", "metadata": {}, "source": [ "# pdf004_Binomial\n", "tutorial illustrating the use of TMath::Binomial\n", "can be run with:\n", "\n", "```cpp\n", "root > .x binomial.C\n", "root > .x binomial.C+ with ACLIC\n", "```\n", "\n", "\n", "\n", "\n", "**Author:** Federico Carminati \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:26 PM." ] }, { "cell_type": "markdown", "id": "8eae538e", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 1, "id": "8e3b6f9a", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:36.128021Z", "iopub.status.busy": "2026-05-19T20:26:36.127910Z", "iopub.status.idle": "2026-05-19T20:26:36.132884Z", "shell.execute_reply": "2026-05-19T20:26:36.132523Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "\n", "#include \n", "#include \n", "\n", "void binomialSimple() {\n", " //\n", " // Simple test for the binomial distribution\n", " //\n", " printf(\"\\nTMath::Binomial simple test\\n\");\n", " printf(\"Build the Tartaglia triangle\\n\");\n", " printf(\"============================\\n\");\n", " const Int_t max=13;\n", " Int_t j;\n", " for(Int_t i=0;i1e-10)\n", " printf(\"res1=%e res2=%e x=%e y=%e err=%e j=%d\\n\",res1,res2,x,y,err,j);\n", " serr +=err;\n", " }\n", " }\n", " printf(\"Average Error = %e\\n\",serr/nmax);\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "id": "f12e9ef6", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:36.140703Z", "iopub.status.busy": "2026-05-19T20:26:36.140570Z", "iopub.status.idle": "2026-05-19T20:26:36.458081Z", "shell.execute_reply": "2026-05-19T20:26:36.457622Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "TMath::Binomial simple test\n", "Build the Tartaglia triangle\n", "============================\n", "n= 0 1\n", "n= 1 1 1\n", "n= 2 1 2 1\n", "n= 3 1 3 3 1\n", "n= 4 1 4 6 4 1\n", "n= 5 1 5 10 10 5 1\n", "n= 6 1 6 15 20 15 6 1\n", "n= 7 1 7 21 35 35 21 7 1\n", "n= 8 1 8 28 56 70 56 28 8 1\n", "n= 9 1 9 36 84 126 126 84 36 9 1\n", "n=10 1 10 45 120 210 252 210 120 45 10 1\n", "n=11 1 11 55 165 330 462 462 330 165 55 11 1\n", "n=12 1 12 66 220 495 792 924 792 495 220 66 12 1\n", "\n", "TMath::Binomial fancy test\n", "Verify Newton formula for (x+y)^n\n", "x,y in [-2,2] and n from 0 to 9 \n", "=================================\n", "Average Error = 1.060390e-13\n" ] } ], "source": [ "binomialSimple();\n", "binomialFancy();" ] } ], "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 }