// // state.sce // // A first order integration of an accelerating mass // // To run this in Scilab use 'File' then 'Exec'. // // by: J. Slater J Briceno // // System component values x1 = 8; // initial conditions v1 = 12; x2 = 9; v2 = 4; ks1=1; ks2=2; ks3=2; kd1=1; kd2=2; kd3=1; m1=100; m2=50; force=100; X=[x1, v1, x2, v2]; // define the state matrix function // the values returned are [x, v] function foo=f(state,t) foo = [ state($, 2), (-ks1-ks2)/m1* state($, 1)+(-kd1-kd2)/m1*state($,2)+ks2/m1*state($,3)+kd2/m1*state($,4), state($, 4), ks2/m2*state($,1)+kd2/m2*state($,2)+(-ks2-ks3)/m2*state($,3)+(-kd2-kd3)/m2*state($,4)-force/m2]; endfunction // Set the time length and step size for the integration steps = 100; t_start = 0; t_end = 1; h = (t_end - t_start) / steps; // // Loop for integration // for i=1:steps, X = [X ; X($,:) + h*f(X, i*h)]; end printf("The value at the end of first order integration is (x, v) = (%f, %f)\n", ... X($,1), ... X($,2), ... X($,3), ... X($,4));