You are on page 1of 4

Modelo pitch

Sistema Masa Resorte

function [xdot]=masa_resorte(x, u)
x1=x(1);
x2=x(2);
ui=u;
// parametros del modelo

k=1;
m=1;
b=1;
xdot=[x2;-(k/m)*x1-(b/m)*x2-(1/m)*ui];

endfunction

Método de Runge-Kutta
En análisis numérico, los métodos de Runge-Kutta son un conjunto de métodos genéricos iterativos,
explícitos e implícitos, de resolución numérica de ecuaciones diferenciales.
Código
function [resp, t]=runge(ta, tb, h, xzero, uzero)
//ta = start time
// tb = end time
// h = step time
// n = number of iterations
n=(tb-ta)/h
resp=xzero;
xant=xzero;
i=1;
t(i)=ta;
j=0;

while j<=1

k1=masa_resorte(xant,uzero);
xk2=(0.5.*h).*k1;
xk21=[xant(1) xant(2);xant(1) xant(2)]+[xk2(1) xk2(1);xk2(2) xk2(2)];
k2=masa_resorte(xk21,uzero);
xk3=(0.5.*h).*k2;
xk22=[xant(1) xant(2);xant(1) xant(2)]+[xk3(1) xk3(1);xk3(2) xk3(2)];
k3=masa_resorte(xk22,uzero);
xk4=(0.5.*h).*k3;
xk23=[xant(1) xant(2);xant(1) xant(2)]+[xk4(1) xk4(1);xk4(2) xk4(2)];
k4=masa_resorte(xk23,uzero);
xx2=(k1+2*k2+2*k3+k4)
xx=[xant(1) xant(2);xant(1) xant(2)]+(h/6)*[xx2(1) xx2(1);xx2(2) xx2(2)];
j=j+1
i=i+1;
xant=xx
aa(:,1)=xzero;
aa(:,i)=xx(:,1)

t(1,i)=ta+(i-1)*h
resp=[aa];
end

while i<=n

k1=masa_resorte(xant,uzero);
xk2=(0.5.*h).*k1;
xk21=xant+[xk2(1) xk2(1);xk2(2) xk2(2)];
k2=masa_resorte(xk21,uzero);
xk3=(0.5.*h).*k2;
xk22=xant+[xk3(1) xk3(1);xk3(2) xk3(2)];
k3=masa_resorte(xk22,uzero);
xk4=(0.5.*h).*k3;
xk23=xant+[xk4(1) xk4(1);xk4(2) xk4(2)];
k4=masa_resorte(xk23,uzero);
xx2=(k1+2*k2+2*k3+k4)
xx=xant+(h/6)*[xx2(1) xx2(1);xx2(2) xx2(2)];

i=i+1;

xant=xx
aa(:,1)=xzero;
aa(:,i)=xx(:,1)

t(1,i)=ta+(i-1)*h
resp=[aa];
end
subplot(2,2,1)
plot(t,resp(1,:))
subplot(2,2,2)
plot(t,resp(2,:))
subplot(2,2,3)
plot(t,resp)
endfunction

You might also like