-
Notifications
You must be signed in to change notification settings - Fork 0
/
kod.cpp
99 lines (80 loc) · 2.02 KB
/
kod.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <cmath>
#include <iostream>
// -----------------------------------------------
// Kod z instrukcji
// -----------------------------------------------
// funkcja liczy wartosc wielomianu interpolacyjnego Lagrange'a
// tablice *x i *y zawieraja wspolrzedne wezlow interpolacji
// n liczba wezlow interpolacji
// xx wartosc dla ktorej liczy sie wielomian
double lagrange(const double *x, const double *y, int n, double xx) {
int i, j;
double yint, ylag;
yint = 0.0;
for (i = 0; i < n; i++) {
ylag = 1.0;
for (j = 0; j < n; j++) {
if (i == j)
continue;
ylag *= (xx - x[j]) / (x[i] - x[j]);
}
yint += y[i] * ylag;
}
return yint;
}
// oblicza calke metoda simpsona
double simpson(double a, double b, double (*pf)(double), int n) {
double x = a;
double h = (b - a) / (2 * n);
double h2 = h * 2;
double x1 = a + h;
double suma = pf(a) + 4. * pf(x1) + pf(b);
for (int i = 0; i < n - 1; i += 1) {
x += h2;
suma += 2. * pf(x) + 4. * pf(x + h);
}
return suma * h / 3.;
}
double bisec(double xa, double xb, double (*pf)(double), double eps,
int *i_iter) {
int i;
double fa, fb, xc, fc;
fa = pf(xa);
fb = pf(xb);
if (fa * fb > 0.0) {
*i_iter = -1;
return 0;
}
for (i = 1; i <= 1000; i++) {
xc = (xa + xb) / 2.;
fc = pf(xc);
if (fa * fc < 0.) {
xb = xc;
fb = fc;
} else {
xa = xc;
fa = fc;
}
if (fabs(fc) < eps && fabs(xb - xa) < eps)
break;
}
*i_iter = i;
return xc;
}
// -----------------------------------------------
const double Cd = .2491326;
const double rho = 1025.;
const double A = 80.;
const double vs = 10.;
const double W = 45'000'000.;
const double M = 40'500.;
const double eta = .25;
const int n = 11;
const double delta_x = 200'000.;
const double pomiary_vw[] = {3., 3.5, 3.6, 3.7, 3., 2.,
1.1, .3, -.4, -1., -1.4};
double rozwiazanie() { return 0.; }
int main() {
const double d = rozwiazanie();
printf("Obliczony dystans: %.1lf\n", d);
}