Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define x0 2
- #define v0 1
- #define t0 0
- #define tf 100
- #define w02 3
- #define dt 1e-2
- #define N ((tf-t0)/dt)
- double dvdt(double x, double v, double t)
- {
- return -w02*x;
- }
- int main(void)
- {
- double x = x0, xn,
- t = t0, tn,
- v = v0, vn;
- int i;
- FILE *h = fopen("./euler.dat","w+");
- for (i = 0; i < N; ++i)
- {
- xn = x + v*dt;
- vn = v + dvdt(x,v,t)*dt;
- tn = t + dt;
- fprintf(h, "%d %f %f\n", i, t, x);
- x = xn;
- v = vn;
- t = tn;
- }
- fclose(h);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement