function [xt,vt] = cork1(pt,x0,v0) % % The function [xt,vt] = cork1(pt,x0,v0) is similar to cork, % but the length of the cork is now 3.76 instead of 3.75. % % ON ENTRY: % pt proposed end time; % x0 initial position of the cork; % v0 initial velocity of the cork. % % ON RETURN: % xt location of the cork at pt; % vt velocity of the cork at pt. % % EXAMPLE: % [xt,vt] = cork(1.2457,0,0). % g = 9.81; % five parameters: (g,q,D,gamma,R) q = 20; D = 5; gamma = 1.4; R = 4; % The length of the cork is L: L = 3.75; % The 2nd order equation is written as a system of two % first-order equations: % f = inline('[x(2); g*(1+q)*((1+x(1)/D)^(-gamma) + R*t/100 - 1 + q*x(1)/(L*(1+q)))]', 't','x'); f = inline('[x(2); 9.81*(1+20)*((1+x(1)/5)^(-1.4) + 4*t/100 - 1 + 20*x(1)/(3.76*(1+20)))]', 't','x'); xzero = [x0 v0]; % initial conditions tspan = [0 pt]; [t x] = ode45(f,tspan,xzero); plot(t,x(:,1),'b'); xt = x(size(x,1),1) vt = x(size(x,1),2)