Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- /*
- Matriz tridiagonal da forma:
- d a 0 0 0 0 x B
- b d a 0 0 0 x B
- 0 b d a 0 0 * x = B
- 0 0 b d a 0 x B
- 0 0 0 b d a x B
- 0 0 0 0 b d x B
- */
- /*
- V = [1 2 3 4 5 6 7 8 9 10]
- dVdx = V(i+1) - V(i)
- -1 1 0 0 0 1 1
- 0 -1 1 0 0 2 1
- 0 0 -1 1 0 * 3 = 1
- 0 0 0 -1 1 4 1
- 0 0 0 0 -1 5 1
- dv = f(x) <=> A * v = f(x)
- */
- #define n 250
- #define C 1
- #define K 6
- #define m 1
- #define omega 0.1
- #define alpha (2*K - m*omega*omega)
- int main(void)
- {
- double a[n], b[n], B[n], x[n], d[n];
- for (int i = 0; i < n; ++i)
- {
- b[i] = -K;
- a[i] = -K;
- d[i] = alpha;
- }
- d[0] -= K;
- d[n-1] -= K;
- a[0] /= d[0];
- B[0] /= d[0];
- for (int i = 1; i < n; ++i)
- {
- a[i] /= d[i] - b[i]*a[i-1];
- B[i] = (B[i] - b[i]*B[i-1])/(d[i] - b[i]*a[i-1]);
- }
- B[n] = (B[n] - b[n]*B[n-1])/(d[n] - b[n]*a[n-1]);
- x[0] = B[0];
- for (int i = n-1; i >= 1; --i)
- {
- x[n] = B[n];
- x[i] = B[i] - a[i]*x[i+1];
- }
- for (int i = 0; i < n; ++i)
- {
- printf("%d %lf\n", i, x[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement