понедельник, 20 декабря 2021 г.
пятница, 17 декабря 2021 г.
пятница, 26 ноября 2021 г.
среда, 24 ноября 2021 г.
пятница, 19 ноября 2021 г.
Numerical, Derivatives
https://codetown.ru/matlab/chislennoe-differencirovanie/
http://qilab.phys.msu.ru/people/zadkov/teaching/seminar1/semnumer1.pdf
http://aco.ifmo.ru/el_books/numerical_methods/lectures/glava1.html
https://kpfu.ru/staff_files/F_1163013414/8_Chislennoe_differencirovanie.pdf
http://qilab.phys.msu.ru/people/zadkov/teaching/seminar1/semnumer1.pdf
среда, 17 ноября 2021 г.
Numerical, Integration
https://en.wikipedia.org/wiki/Numerical_integration
https://www.whitman.edu/mathematics/calculus_online/section08.06.html
https://opentextbc.ca/calculusv2openstax/chapter/numerical-integration/
https://mathworld.wolfram.com/NumericalIntegration.html
https://www.sfu.ca/math-coursenotes/Math%20158%20Course%20Notes/sec_Numerical_Integration.html
https://www.sciencedirect.com/topics/mathematics/numerical-integration
https://www.gnu.org/software/gsl/doc/html/integration.html
https://www.mathworks.com/help/matlab/ref/integral.html
https://en.wikipedia.org/wiki/Trapezoidal_rule
https://math24.net/trapezoidal-rule.html
вторник, 16 ноября 2021 г.
Simpson, Cotes, Newton
https://en.wikipedia.org/wiki/Thomas_Simpson
https://en.wikipedia.org/wiki/Roger_Cotes
https://ru.wikipedia.org/wiki/%D0%9A%D0%BE%D1%82%D1%81,_%D0%A0%D0%BE%D0%B4%D0%B6%D0%B5%D1%80
https://en.wikipedia.org/wiki/Isaac_Newton
https://ru.wikipedia.org/wiki/%D0%9D%D1%8C%D1%8E%D1%82%D0%BE%D0%BD,_%D0%98%D1%81%D0%B0%D0%B0%D0%BA
понедельник, 8 ноября 2021 г.
четверг, 4 ноября 2021 г.
Probability, density, function, PDF
https://en.wikipedia.org/wiki/Probability_density_function
https://en.wikipedia.org/wiki/Fair_coin
https://online.stat.psu.edu/stat414/lesson/14/14.1
http://statistica.ru/glossary/general/plotnost-raspredeleniya-veroyatnostey/
http://mathprofi.ru/nepreryvnaya_sluchaynaya_velichina.html
https://math.semestr.ru/math/expectation-continuous.php
https://yukhym.com/ru/sluchajnye-velichiny/plotnost-raspredeleniya-veroyatnostej.html
https://congyuzhou.medium.com/%D0%BF%D0%BB%D0%BE%D1%82%D0%BD%D0%BE%D1%81%D1%82%D1%8C-%D1%80%D0%B0%D1%81%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F-%D0%B2%D0%B5%D1%80%D0%BE%D1%8F%D1%82%D0%BD%D0%BE%D1%81%D1%82%D0%B5%D0%B9-31d19a680f16
среда, 3 ноября 2021 г.
generate, normally, distributed, random, numbers, Box–Muller, Box, Muller, algorithm
Box–Muller
https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
https://star-wiki.ru/wiki/Box%E2%80%93Muller_transform
https://medium.com/mti-technology/how-to-generate-gaussian-samples-3951f2203ab0
https://mathworld.wolfram.com/Box-MullerTransformation.html
https://www.statisticshowto.com/box-muller-transform-simple-definition/
суббота, 30 октября 2021 г.
Cpp, CDF, erfx, Stackoverflow
Cpp, CDF, erfx, Stackoverflow
https://en.cppreference.com/w/cpp/numeric/math/erfc
#include <iostream>
#include <cmath>
#include <iomanip>
double normalCDF(double x) // Phi(-∞, x) aka N(x)
{
return std::erfc(-x/std::sqrt(2))/2;
}
int main()
{
std::cout << "normal cumulative distribution function:\n"
<< std::fixed << std::setprecision(2);
for(double n=0; n<1; n+=0.1)
std::cout << "normalCDF(" << n << ") " << 100*normalCDF(n) << "%\n";
std::cout << "special values:\n"
<< "erfc(-Inf) = " << std::erfc(-INFINITY) << '\n'
<< "erfc(Inf) = " << std::erfc(INFINITY) << '\n';
}
http://poivs.tsput.ru/ru/Math/Functions/SpecialFunctions/ErrorFunction
----------------------------------------------------------------------------------------------------------
Stackoverflow
-----------------------------------------------------------------------------------------------------------------------
https://stackoverflow.com/questions/2328258/cumulative-normal-distribution-function-in-c-c
https://en.wikipedia.org/wiki/Error_function
https://en.m.wikipedia.org/wiki/Normal_distribution
---------------------------------------------------------------------------------------------------------------------
Theres is no straight function. But since the gaussian error function and its complementary function is related to the normal cumulative distribution function (see here, or here) we can use the implemented c-function erfc (complementary error function):
double normalCDF(double value)
{
return 0.5 * erfc(-value * M_SQRT1_2);
}
Which considers the relation of erfc(x) = 1-erf(x) with M_SQRT1_2 = √0,5.
I use it for statistical calculations and it works great. No need for using coefficients.
------------------------------------------------------------------------------------------------
#ifndef Pi
#define Pi 3.141592653589793238462643
#endif
double cnd_manual(double x)
{
double L, K, w ;
/* constants */
double const a1 = 0.31938153, a2 = -0.356563782, a3 = 1.781477937;
double const a4 = -1.821255978, a5 = 1.330274429;
L = fabs(x);
K = 1.0 / (1.0 + 0.2316419 * L);
w = 1.0 - 1.0 / sqrt(2 * Pi) * exp(-L *L / 2) * (a1 * K + a2 * K *K + a3 * pow(K,3) + a4 * pow(K,4) + a5 * pow(K,5));
if (x < 0 ){
w= 1.0 - w;
}
return w;
}----------------------------------------------------------------------------------------------------------------------------------
double
phi(double x)
{
static const double RT2PI = sqrt(4.0*acos(0.0));
static const double SPLIT = 7.07106781186547;
static const double N0 = 220.206867912376;
static const double N1 = 221.213596169931;
static const double N2 = 112.079291497871;
static const double N3 = 33.912866078383;
static const double N4 = 6.37396220353165;
static const double N5 = 0.700383064443688;
static const double N6 = 3.52624965998911e-02;
static const double M0 = 440.413735824752;
static const double M1 = 793.826512519948;
static const double M2 = 637.333633378831;
static const double M3 = 296.564248779674;
static const double M4 = 86.7807322029461;
static const double M5 = 16.064177579207;
static const double M6 = 1.75566716318264;
static const double M7 = 8.83883476483184e-02;
const double z = fabs(x);
double c = 0.0;
if(z<=37.0)
{
const double e = exp(-z*z/2.0);
if(z<SPLIT)
{
const double n = (((((N6*z + N5)*z + N4)*z + N3)*z + N2)*z + N1)*z + N0;
const double d = ((((((M7*z + M6)*z + M5)*z + M4)*z + M3)*z + M2)*z + M1)*z + M0;
c = e*n/d;
}
else
{
const double f = z + 1.0/(z + 2.0/(z + 3.0/(z + 4.0/(z + 13.0/20.0))));
c = e/(RT2PI*f);
}
}
return x<=0.0 ? c : 1-c;
}
-------------------------------------------------------------------------------------------------------------------------
static double CND(double d)
{
const double A1 = 0.31938153;
const double A2 = -0.356563782;
const double A3 = 1.781477937;
const double A4 = -1.821255978;
const double A5 = 1.330274429;
const double RSQRT2PI = 0.39894228040143267793994605993438;
double
K = 1.0 / (1.0 + 0.2316419 * fabs(d));
double
cnd = RSQRT2PI * exp(- 0.5 * d * d) *
(K * (A1 + K * (A2 + K * (A3 + K * (A4 + K * A5)))));
if (d > 0)
cnd = 1.0 - cnd;
return cnd;
}
--------------------------------------------------------------------------------------------------------
john cook
#include <cmath>
double phi(double x)
{
// constants
double a1 = 0.254829592;
double a2 = -0.284496736;
double a3 = 1.421413741;
double a4 = -1.453152027;
double a5 = 1.061405429;
double p = 0.3275911;
// Save the sign of x
int sign = 1;
if (x < 0)
sign = -1;
x = fabs(x)/sqrt(2.0);
// A&S formula 7.1.26
double t = 1.0/(1.0 + p*x);
double y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);
return 0.5*(1.0 + sign*y);
}
void testPhi()
{
// Select a few input values
double x[] =
{
-3,
-1,
0.0,
0.5,
2.1
};
// Output computed by Mathematica
// y = Phi[x]
double y[] =
{
0.00134989803163,
0.158655253931,
0.5,
0.691462461274,
0.982135579437
};
int numTests = sizeof(x)/sizeof(double);
double maxError = 0.0;
for (int i = 0; i < numTests; ++i)
{
double error = fabs(y[i] - phi(x[i]));
if (error > maxError)
maxError = error;
}
std::cout << "Maximum error: " << maxError << "\n";
}