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