Caida libre, solucion exacta

Consideremos la solucion de

    \[y=y_0+v_0 t-\frac{1}{2}gt^2\]


donde las condiciones iniciales son y_0 y v_0

Un programa en c++ puede ser algo como

// caida_00.cpp
#include <iostream>
#include <complex>
#include <fstream> 
#include <sstream>
using namespace std;
double g   = 9.8;
int main()
{
 float y0,v0,y;
 float t,ti,tf,dt;int it,Nt=9; 
 y0	=	100.0;
 v0	=	0.0;
 
 ti	=	0.0;
 tf	=	5.0;
 dt	=	(tf-ti)/float(Nt);
 

 for(it=0;it<Nt;it++)
 {
  t	=	ti+dt*float(it);
  y	=	y0+v0*t-0.5*g*t*t;
  cout<<t<<" "<<y<<"\n";
 }

  
}

Este programa se compila con

g++ caida_00.cpp./a.out
0 100
0.555556 98.4877
1.11111 93.9506
1.66667 86.3889
2.22222 75.8025
2.77778 62.1914
3.33333 45.5555
3.88889 25.8951
4.44444 3.20987

Aqui tenemos los datos a pantalla.

Ahora, este mismo programa en fortran es

program newton_10
implicit none

real    :: y0,v0,y,g=9.8
real    :: t,ti,tf,dt
integer :: it,Nt=9

y0	=	100.0;
v0	=	0.0;
 
ti	=	0.0;
tf	=	5.0;
dt	=	(tf-ti)/real(Nt);

do it   = 0,Nt
t	=	ti+dt*float(it)
y	=	y0+v0*t-0.5*g*t*t
write(*,*)it,t,y
enddo

end program

grama se compila con

gfortran caida_00.f90 ./a.out > a.dat
cat a.dat            0   0.00000000       100.000000                1  0.555555582       98.4876556                2   1.11111116       93.9506149                3   1.66666675       86.3888855                4   2.22222233       75.8024673                5   2.77777791       62.1913528                6   3.33333349       45.5555496                7   3.88888907       25.8950500                8   4.44444466       3.20986938                9   5.00000000      -22.5000000     </code></pre> <!-- /wp:code -->  <!-- wp:paragraph --> Ahora, el programa lo compilamos y al correr, en vez de sacar los datos a pantalla, los datos fueron enviados al archivo 'a.dat' <!-- /wp:paragraph -->  <!-- wp:paragraph --> Finalmente, consideramos el caso de python, tenemos <!-- /wp:paragraph -->  <!-- wp:enlighter/codeblock --> <pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">g	=	9.8 y0	=	100 v0	=	0  ti	=	0 tf	=	5 Nt	=	9 dt	=	(tf-ti)/Nt   for it in range(9):   t	=	ti+it*dt   y     =       y0+v0*t-0.5*g*t*t   print(it,t,y)</pre> <!-- /wp:enlighter/codeblock -->  <!-- wp:paragraph -->  <!-- /wp:paragraph -->  <!-- wp:paragraph --> este programa se corre con <!-- /wp:paragraph -->  <!-- wp:code --> <pre class="wp-block-code"><code>python3 caida_00.py
0 0.0 100.0
1 0.5555555555555556 98.48765432098766
2 1.1111111111111112 93.95061728395062
3 1.6666666666666667 86.38888888888889
4 2.2222222222222223 75.80246913580247
5 2.7777777777777777 62.191358024691354
6 3.3333333333333335 45.55555555555554
7 3.8888888888888893 25.89506172839505
8 4.444444444444445 3.209876543209873

esta salida la podemos sacar a un archivo ,con la instruccion

python3 caida_00.py > b.dat jesus@COVID:~/Dropbox/2020/10_2020/FDTD cat b.dat
0 0.0 100.0
1 0.5555555555555556 98.48765432098766
2 1.1111111111111112 93.95061728395062
3 1.6666666666666667 86.38888888888889
4 2.2222222222222223 75.80246913580247
5 2.7777777777777777 62.191358024691354
6 3.3333333333333335 45.55555555555554
7 3.8888888888888893 25.89506172839505
8 4.444444444444445 3.209876543209873