function ydot = weightf(t, y) % WEIGHTF : function for the harmonic oscillator ODE % % The differential equation is ydot = weightf(t, y) % % t: time, a scalar. % y: unknown function of time: y = y(t). Can be a vector. % % ydot: time derivative of y: dy/dt. Vector the same size as y. % % This illustrates how to transform an ODE with a second derivative % into a system of ODEs with just first derivatives. % The 2nd-order ODE is x'' = 1-x, with initial conditions x(0) and x'(0). % In the 1st-order ODE, y has two components: y(1)=x and y(2)=x' ydot = [ y(2) ; 1-y(1)];