Guest User

Untitled

a guest
Jul 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define g 9.81
  4.  
  5.  
  6. typedef struct punto{
  7.    double x,y,z;
  8. }Punto;
  9. double calculo(double v,double t,double vrel,double tf,double t0,double M0,double R){
  10.    double res,ln;
  11.    ln=log(1 + (R*(tf-t0)/M0));
  12.    res=v*t - (0.5)*g*t*t - vrel*((tf-t0) - (M0/R + (tf-t0))*ln);
  13.    return res;
  14. }
  15.  
  16. int main(){
  17.    Punto d,v,final_rel,final,vrel;
  18.    double t0,tf,t,h,M0,R;
  19.    int n;  
  20.    printf("\t***Calculo de los puntos de trayectoria de un cohete de masa variable***\n");
  21.    printf("Ingrese el tiempo inicial(s):\n");
  22.    scanf("%lf",&t0);
  23.    printf("Ingrese la posicion inicial(m):\n");
  24.    printf("X: "); scanf("%lf",&d.x);
  25.    printf("Y: "); scanf("%lf",&d.y);
  26.    printf("Z: "); scanf("%lf",&d.z);
  27.    printf("Ingrese la velocidad inicial(m/s):\n");
  28.    printf("X: "); scanf("%lf",&v.x);
  29.    printf("Y: "); scanf("%lf",&v.y);
  30.    printf("Z: "); scanf("%lf",&v.z);
  31.    printf("Ingrese la masa inicial (kg):\n");
  32.    scanf("%lf",&M0);
  33.    printf("ingrese el tiempo final(s):\n");
  34.    scanf("%lf",&tf);   
  35.    printf("Ingrese la cantidad de puntos:\n");   
  36.    scanf("%d",&n);
  37.    while(n==0){
  38.      printf("ingrese otra cantidad:\n");
  39.      scanf("%d",&n);
  40.    }
  41.    printf("Ingrese el valor de R(Kg/s) y R<0:\n");
  42.    scanf("%lf",&R);
  43.    printf("Ingrese la velocidad relativa(m/s):\n");
  44.    printf("X: "); scanf("%lf",&vrel.x);
  45.    printf("Y: "); scanf("%lf",&vrel.y);
  46.    printf("Z: "); scanf("%lf",&vrel.z);   
  47.    
  48.    h=(tf-t0)/n;
  49.    for (t=t0; t<=tf; t+=h){
  50.    final_rel.x= calculo(v.x,t,vrel.x,tf,t0,M0,R);   
  51.    final_rel.y= calculo(v.y,t,vrel.y,tf,t0,M0,R);
  52.    final_rel.z= calculo(v.z,t,vrel.z,tf,t0,M0,R);
  53.    printf("%lf\t %lf\t %lf \n",final_rel.x,final_rel.y,final_rel.z);
  54.    }   
  55.    printf("\n");
  56.    printf("La posicion final es: xf= %lf  yf= %lf  zf= %lf\n",final_rel.x,final_rel.y,final_rel.z);   
  57.    return 0;
  58. }
Add Comment
Please, Sign In to add comment