Está en la página 1de 3

// Funciones del programa para la velcidad, posicion x-y, presion y el alcance

// Funci�n para la velocidad


function Velocidadc=d1(ti,v,y,p,Vw);
Velocidadc=((((p-P_atm)*Ac)-(D*vv))/(0.085+(rho*Vw)));
endfunction

// Funci�n para la posici�n x,y

function Posicion=d2(ti,v,y,p,Vw);
Posicion=v;
endfunction

//Funci�n para la presi�n en cohete

function Presion=d3(ti,v,y,p,Vw);
Presion=(-((p)/(0.002-Vw))*(Ac*sqrt(abs((2*(p-P_atm))/(rho)))));
endfunction

//Funci�n para volumen de agua

function Volumenw=d4(ti,v,y,p,Vw)
Volumenw=(-Ac*sqrt(abs((2*(p-P_atm))/(rho))));
endfunction

//Par�metros

rho=1000; // Densidad del agua [kg/m3]


g=9.81; // gravedad
Ac=0.00005026548246; //�rea boquilla salida de agua
P_atm=101125; // presi�n atm (1 atm) [Pa]
D=0.0002;

//Condiciones iniciales

t(1)=0; // Tiempo [s]


V(1)=0; // Velocidad [m/s]
Y(1)=0; // Posici�n [m]
P(1)=405300; //Presi�n (4 atm) [Pa]
V_w(1)=0.0004; // Volumen de agua [m3]
TS=3.3; //Tiempo total de simu

dt=1e-4; //[Paso de tiempo

Iter=floor(TS/dt);// Aplicacion del metodo de Runge-Kutta para 4 Rk4


for i=2:Iter
t(i)=t(i-1)+dt;

//funciones del paso 1


Ftemp(1,1)=d1(t(i-1),V(i-1),Y(i-1),P(i-1),V_w(i-1))
Ftemp(1,2)=d2(t(i-1),V(i-1),Y(i-1),P(i-1),V_w(i-1))
Ftemp(1,3)=d3(t(i-1),V(i-1),Y(i-1),P(i-1),V_w(i-1))
Ftemp(1,4)=d4(t(i-1),V(i-1),Y(i-1),P(i-1),V_w(i-1))

//funciones del paso 2


Ftemp(2,1)=d1(t(i-1)+dt*0.5,V(i-1)+Ftemp(1,1)*0.5*dt,Y(i-1)+Ftemp(1,2)*0.5*dt,P(i-
1)+Ftemp(1,3)*0.5*dt,V_w(i-1)+Ftemp(1,4)*0.5*dt)
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Ftemp(3,3)*dt,V_w(i-1)+Ftemp(3,4)*dt)

Ftemp(4,2)=d2(t(i-1)+dt,V(i-1)+Ftemp(3,1)*dt,Y(i-1)+Ftemp(3,2)*dt,P(i-
1)+Ftemp(3,3)*dt,V_w(i-1)+Ftemp(3,4)*dt)

Ftemp(4,3)=d3(t(i-1)+dt,V(i-1)+Ftemp(3,1)*dt,Y(i-1)+Ftemp(3,2)*dt,P(i-
1)+Ftemp(3,3)*dt,V_w(i-1)+Ftemp(3,4)*dt)

Ftemp(4,4)=d4(t(i-1)+dt,V(i-1)+Ftemp(3,1)*dt,Y(i-1)+Ftemp(3,2)*dt,P(i-
1)+Ftemp(3,3)*dt,V_w(i-1)+Ftemp(3,4)*dt)

//Resultados

//Velocidad
V(i)=V(i-1)+dt*(Ftemp(1,1)+2*Ftemp(2,1)+2*Ftemp(3,1)+Ftemp(4,1))/6;

//Posicion
Y(i)=Y(i-1)+dt*(Ftemp(1,2)+2*Ftemp(2,2)+2*Ftemp(3,2)+Ftemp(4,2))/6;

// Volumen

V_w(i)=V_w(i-1)+dt*(Ftemp(1,4)+2*Ftemp(2,4)+2*Ftemp(3,4)+Ftemp(4,4))/6;

// Presion

P(i)=P(i-1)+dt*(Ftemp(1,3)+2*Ftemp(2,3)+2*Ftemp(3,3)+Ftemp(4,3))/6;

//Gr�ficas
// Velocidad
subplot(2,2,1)
xgrid
plot(t,V)
title("Curva de velocidad del cohete vs tiempo");
xlabel("Tiempo[s]");
ylabel("Velocidad[m/s]]");
subplot(2,2,2)
xgrid
end

//Posicion
plot(t,Y)
title("Curva de posici n del cohete vs tiempo");
xlabel("Tiempo[s]");
ylabel(" Posici n[m]");
subplot(2,2,3)
xgrid
//Presion
plot(t,P)
title("Curva de presi n del cohete vs tiempo");
xlabel("Tiempo[s]");
ylabel(" Presi n[Pa]");
subplot(2,2,4)//
xgrid
//Volumen
plot(t,V_w)
title("Curva de volumen de agua en el cohete vs tiempo");
xlabel("Tiempo[s]");
ylabel("Volumen[m3]");

También podría gustarte