-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-euler_cromer.c
More file actions
57 lines (48 loc) · 847 Bytes
/
Copy path05-euler_cromer.c
File metadata and controls
57 lines (48 loc) · 847 Bytes
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
//////////////////////
////EULER EXPLICITO///
//////////VS//////////
/////EULER-CROMER/////
/////PEDRO MENDES/////
//////////////////////
#include<stdio.h>
#include<math.h>
int main ()
{
int m;
double x, xi, deltat, v, t, w, tf;
double g, l;
printf("\n #Insira um valor do passo:\n\n");
scanf("%lf", &deltat);
x = 0.1;
v = 0;
g = 10;
l = 10;
w = g/l;
t = 0;
tf = 30;
printf("\n#Escolha o metodo\n#Euler-Explicito(0)\n#Euler-Cromer(1)\n\n");
scanf("%d", &m);
printf("%lf %lf\n", t, x);
if(m==0) //euler explicito
{
while(t < tf)
{
xi = x;
x = x + v*deltat;
v = v - w*sin(xi)*deltat;
t = t + deltat;
printf("%lf %lf\n", t, x);
}
}
else //euler-cromer
{
while(t < tf)
{
x = x + v*deltat;
v = v - w*sin(x)*deltat;
t = t + deltat;
printf("%lf %lf\n", t, x);
}
}
return 0;
}