From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Aufgabe2und3/src/Normaldistribution.cpp | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/Normaldistribution.cpp (limited to 'Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/Normaldistribution.cpp') diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/Normaldistribution.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/Normaldistribution.cpp new file mode 100644 index 0000000..5c9370b --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/Normaldistribution.cpp @@ -0,0 +1,64 @@ +/* + * Normaldistribution.cpp + * + * Created on: 20.05.2011 + * Author: sven + */ + +#include "Normaldistribution.h" +#include +#include +#include + +Normaldistribution::Normaldistribution() { +} + +Normaldistribution::~Normaldistribution() { +} + +void Normaldistribution::calcRandomVector(const CholeskyMatrix& D, const std::vector& mu , std::vector& y) +{ + std::vector u(nenEndOfCompanies); + calcStandardNormalDistributedRandomVector(nenEndOfCompanies,u); + for (int i=0;i& u) +{ + double x1,x2; + double v1,v2; + double u1,u2; + double s; + int counter = 0; + while (counter < size) + { + do + { + x1 = ((double) rand()) / (RAND_MAX + 1.0); + x2 = ((double) rand()) / (RAND_MAX + 1.0); + v1 = (2.0 * x1) - 1.0; + v2 = (2.0 * x2) - 1.0; + s = (v1*v1) + (v2*v2); + } while (s >= 1.0); + u1 = v1 * std::sqrt( - (2.0 / s) * std::log(s) ); + u2 = v2 * std::sqrt( - (2.0 / s) * std::log(s) ); + if (counter < size) { + u.at(counter) = u1; + counter++; + } + if (counter < size) { + u.at(counter) = u2; + counter++; + } + } +} -- cgit v1.2.3