Skip to content
Snippets Groups Projects
Commit cf2a90bb authored by Brayan Santiago Amorocho Lizcano's avatar Brayan Santiago Amorocho Lizcano
Browse files

Upload New File

parent d9843978
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <cmath>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
int main(){
// Introducimos la velocidad y el ángulo
double vel_0, angle, t_max, n;
float g = 9.8;
cout << "Introduzca la velocidad inicial: ";
cin >> vel_0;
cout << "Introduzca el ángulo inicial: ";
cin >> angle;
cout << "Introduzca el número de particiones: ";
cin >> n;
angle = angle * M_PI /180;
// Calculamos las velocidades iniciales
double v_x, v_y0, df;
v_x = vel_0 * cos(angle);
v_y0 = vel_0 * sin(angle);
// Calculamos el tiempo máximo para determinar el ancho de las particiones
t_max = 2*v_y0/g;
df = t_max/n;
//Calculamos la posición y la velocidad en un instante i
std::vector<double> vy, x, y;
for( int i=0; i<n; i++){
x.push_back(v_x*(df*i));
y.push_back(v_y0*(df*i) - g*pow(df*i,2)/2);
vy.push_back(v_y0-g*df*i);
}
// Guardamos los datos en un archivo de texto
ofstream archivo;
archivo.open("Velocidades en Y.txt");
archivo << "Tiempo" << " , " << "Velocidad" << " , " << "X" << " , " << "Y" << endl;
for (int i=0; i<n; i++){
// std::string number = std::to_string(i);
archivo << i << " , " << vy[i] << " , " << x[i] << " , " << y[i] << endl;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment