REQUIRE "ivpsystem.a4l"; REQUIRE "atoms.a4l"; IMPORT "johnpye/extpy/extpy"; IMPORT "johnpye/solve"; MODEL pendulum; x IS_A delta_distance; y IS_A delta_distance; r IS_A distance; theta IS_A angle; -y = r*cos(theta); x = r*sin(theta); m IS_A mass; v_x IS_A speed; v_y IS_A speed; a_x IS_A acceleration; a_y IS_A acceleration; g IS_A acceleration; t IS_A time; (* equations of motion *) Fc IS_A force; +Fc*cos(theta)-m*g = m*a_y; -Fc*sin(theta) = m*a_x; METHODS METHOD specify; FIX r, m, g, x, t; FIX v_x; END specify; METHOD default_self; y := -sqrt(3)/2*(1{m}); x := 0.5 {m}; r := 1 {m}; v_y := 0 {m/s}; v_x := 0 {m/s}; END default_self; METHOD values; t := 0 {s}; r := 1 {m}; m := 1 {kg}; g := 9.8 {N/kg}; END values; METHOD set_ode; (* LINK syntax to set the ode relationships in the procedural part *) DER(v_x, x ); DER(a_x,v_x); DER(v_y, y ); DER(a_y,v_y); INDEPENDENT t; (* Note: In this case there is no longer the need to create two more variables v_x1 and v_y1, even though they belong to two derivative chains with different types, because their types are taken from the link structure rather than from the varaible children *) END set_ode; METHOD set_obs; x.obs_id :=1; y.obs_id :=2; END set_obs; METHOD on_load; RUN default_self; RUN reset; RUN specify; EXTERNAL solve(SELF); EXTERNAL solve(SELF); RUN set_obs; RUN set_ode; END on_load; END pendulum;