Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define _USE_MATH_DEFINES
- #include <math.h>
- #define G 9.80665
- #define N 1000
- double f(double t) {
- return 780. * cos(M_PI_4);
- }
- double g(double t) {
- return 780. * sin(M_PI_4) - G * t;
- }
- void runge(int n, double t_begin, double t_end, double x0, double y0, double *x,
- double *y) {
- int i;
- double t, h, h2, f1, f2, f3, f4, g1, g2, g3, g4;
- t = t_begin;
- h = (t_end - t_begin) / n;
- h2 = h / 2;
- *x = x0;
- *y = y0;
- for (i = 1; i <= n; i++) {
- f1 = h * f(t);
- f2 = h * f(t + h2);
- f3 = h * f(t + h2);
- f4 = h * f(t + h);
- g1 = h * g(t);
- g2 = h * g(t + h2);
- g3 = h * g(t + h2);
- g4 = h * g(t + h);
- t += h;
- *x += (f1 + 2 * f2 + 2 * f3 + f4) / 6;
- *y += (g1 + 2 * g2 + 2 * g3 + g4) / 6;
- }
- }
- int main(void) {
- double t_begin = 0., t_end = 1000., x0 = 0., y0 = 0., x, y;
- runge(N, t_begin, t_end, x0, y0, &x, &y);
- printf("% -lf % -lf\n", x, y);
- printf("% -lf % -lf\n", 780. * cos(M_PI_4) * 1000.,
- 780. * sin(M_PI_4) * 1000. - G / 2. * 1000. * 1000.);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement