Файл weibullDF.h
#ifndef __WEIBULL_H__ /* To prevent redefinition */
#define ENTRY extern #define LOCAL static
ENTRY double weibullDF(double x, double a, double b); ENTRY double inv_weibullDF(double q, double a, double b);
#define __WEIBULL_H__ /* Prevents redefinition */ #endif /* Ends #ifndef__WEIBULL_H__ */
Файл weibullDF.cpp
#include <assert.h> #include <math.h>
double weibullDF(double x, double b, double c) { assert((b > 0) && (c > 0)); double y = 1-exp(-pow(x/b,c)); return y; }
double inv_weibullDF(double q, double b, double c) { assert((b > 0) && (c > 0) && (q >= 0) && (q < 1)); return q==0 ? 0 : b*pow(-log(1-q),1/c); }
#ifdef TEST
#include <iostream>
void main(void) { double b, c;
while (1) { cout << "\n\n\rEnter b: "; cin >> b; if (b <= 0) break; cout << "Enter c: "; cin >> c;
for(double x=0; x < 8; x += 0.32) { double y=weibullDF(x, b, c); cout << "x=" << x << "\tw=" << y; double z=inv_weibullDF(y, b, c); cout << "\tiw=" << z << endl; } } }
#endif
1 2
8 8 8
|