Consideremos la solucion de
![]()
donde las condiciones iniciales son
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
./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
./a.out > a.dat
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
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