# Calculus Exploration 5: Motion in 1 Dimension # # The following is the Maple code for the 1-D Motion Maplet. In this exploration, you should use the 1-D Motion Maplet to investigate position, velocity, and acceleration functions, i.e. s(t), v(t), and a(t), for motion in 1 dimension with with both constant and nonconstant acceleration. # # 1-D Motion # Click in red area and press [Enter]. # Original Author: Douglas Meade # Modified to the current version by John Pais, 10-02-05 restart: LinMotionEval := proc( EXPR, S, V, A, t, T, old_str ) local str, val1, val2; val1 := eval( EXPR, [ s=S, v=V, a=A ] ); val2 := eval( val1, t = T ); str := sprintf( "%a = %a, when %a = %a", EXPR, val2, t, T ); return str end proc: LinMotionSolve := proc( EQN, S, V, A, t, old_str ) local eqn, sol, str; eqn := eval( EQN, [ s=S, v=V, a=A ] ); sol := solve( eqn, t ); str := sprintf( "%a, for %a=%a", EQN, t, {sol}); return str end proc: LinMotionPlot := proc( S, V, A, t, T, Y, EXEC ) local p_list, c_list, s_list, ls_list, cmd; p_list := NULL; c_list := NULL; s_list := NULL; ls_list := NULL; if S[2] then p_list := p_list, S[1]; c_list := c_list, S[3]; if S[4]='POINT' then s_list := s_list, S[4]; ls_list := ls_list, 'SOLID'; else s_list := s_list, 'LINE'; ls_list := ls_list, S[4]; end if end if; if V[2] then p_list := p_list, V[1]; c_list := c_list, V[3]; if V[4]='POINT' then s_list := s_list, V[4]; ls_list := ls_list, 'SOLID'; else s_list := s_list, 'LINE'; ls_list := ls_list, V[4]; end if end if; if A[2] then p_list := p_list, A[1]; c_list := c_list, A[3]; if A[4]='POINT' then s_list := s_list, A[4]; ls_list := ls_list, 'SOLID'; else s_list := s_list, 'LINE'; ls_list := ls_list, A[4]; end if end if; cmd := sprintf( "plot( %a, %a=%a, view=[%a,%a], color=%a, style=%a, linestyle=%a )", [p_list], t, T, T, Y, [c_list], [s_list], [ls_list] ); if EXEC then return parse( cmd, statement ) else return cmd end if end proc: _COLORS := ['blue', 'cyan', 'brown', 'gold', 'green', 'khaki', 'magenta', 'maroon', 'orange', 'pink', 'plum', 'red', 'sienna', 'tan', 'turquoise', 'violet', 'wheat', 'yellow']: _STYLES := ['SOLID', 'POINT','DOT','DASHDOT']: use Maplets, Maplets:-Elements in LinMotion := Maplet( ################ window layout ################ Window( 'title' = "Analysis of Motion in 1 Dimension", BoxRow( 'hscroll' = as_needed, 'vscroll' = as_needed, [ # c 1 - plot window and control [ # r 1 Plotter['PL1']( 'height' = 400, plot( -4.9*t^2+5*t+12, t=0..5,color=blue, view=[0..5,0..15] ) ) ], # r 1 [ # r 2 GridLayout( [ # c 1 [ # r 1 "Horizontal axis", TextField['t0']( 'value' = 0, 'width' = 4 ), " <= ", TextField['t']( 'value' = "t", 'width' = 4, editable=false, 'onchange' = Action(Evaluate('t2'='sprintf("%s =",t)'), Evaluate( 'v' = 'diff(s,t)' ), Evaluate( 'a' = 'diff(v,t)' ) ) ), " <= ", TextField['t1']( 'value' = 5, 'width' = 4 ) ], # r 1 [ # r 2 "Vertical axis", TextField['y0']( 'value' =0, 'width' = 4 ), " <= ", TextField['y']( 'value' = "s", 'width' = 4, editable=false ), " <= ", TextField['y1']( 'value' = 15, 'width' = 4 ) ] # r 2 ] # c 1 ) ], # r 2 ############################### Interchanged row 4 and row 3 [ # r 4 Button( "Display Functions and Plot", 'onclick' = Evaluate('PL1' = 'LinMotionPlot( [s,s_plot,s_color,s_style], [v,v_plot,v_color,v_style], [a,a_plot,a_color,a_style], t, t0..t1, y0..y1, true )') ), Button( "Reset to Original Functions", 'onclick' = 'reset' ), Button( "Exit", Shutdown() ) ], # r 4 ############################### [ # r 3 - plot command BoxLayout( 'border' = true, 'caption' = "Plot Commands", [ [ TextBox['plot_cmds']( 4..50 ) ], [ Button( "Show plot command", 'onclick' = 'show_cmd' ), Button( "Clear plot commands", 'onclick' = SetOption( 'plot_cmds' = " " ) ) ] ] ) ] # r 3 ############################### ], [ # c 2 - pos, vel, acc [ # r 1 - position BoxLayout( 'border' = true, 'caption' = "Position", [ [ "s(t) =", TextField['s']( 'value' = "-4.9*t^2+5*t+12", 'onchange' = Action(Evaluate( 'v' = 'diff(s,t)' ), Evaluate( 'a' = 'diff(v,t)' ) ), 'width' = 30 ) ], [ CheckBox['s_plot']( 'value' = 'true', 'caption' = "Include in plot" ), "Color:", ComboBox['s_color']( 'blue', _COLORS ), "Style:", ComboBox['s_style']( 'SOLID', _STYLES ) ] ] ) ], # r 1 [ # r 2 - velocity BoxLayout( 'border' = true, 'caption' = "Velocity", [ [ "v(t) =", TextField['v']( 'value' = "-9.8*t+5", 'onchange' = Evaluate( 'a' = 'diff(v,t)' ), 'width' = 30 ) ], [ CheckBox['v_plot']( 'value' = 'false', 'caption' = "Include in plot" ), "Color:", ComboBox['v_color']( 'red', _COLORS ), "Style:", ComboBox['v_style']( 'SOLID', _STYLES ) ] ] ) ], # r 2 [ # r 3 - acceleration BoxLayout( 'border' = true, 'caption' = "Acceleration", [ [ "a(t) =", TextField['a']( 'value' = "-9.8", 'width' = 30 ) ], [ CheckBox['a_plot']( 'value' = 'false', 'caption' = "Include in plot" ), "Color:", ComboBox['a_color']( 'magenta', _COLORS ), "Style:", ComboBox['a_style']( 'SOLID', ['SOLID', 'POINT','DOT','DASH','DASHDOT'] ) ] ] ) ], # r 3 [ # r 4 - evaluate or solve BoxLayout( 'border' = true, 'caption' = "Evaluate functions s, v, a and/or solve equation involving s, v, a.", [ [ "Enter function (use s, v, a)", TextField['expr']( 'value' = "", 'width' = 5 ), "enter ", TextField['t2']( 'value' = "t = ", width=3, editable=false ), TextField['t_value']( 'value' = "", 'width' = 10 ) ], ################### Reorganized this section [Button( "Evaluate function at given value", 'onclick' = 'eval_expr' )], [ "Enter equation to be solved (use s, v, a)", TextField['eqn']( 'value' = "", 'width' = 20 ) ], [Button( "Attempt to solve equation", 'onclick' = 'solve_eqn' )], [ TextBox['results']( 4..50, "", 'editable' = false )#, 'quotedtext' = true ) ], [ Button( "Clear results", 'onclick' = SetOption( 'results' = '""' ) ) ] ] ) ] # end r 4 ] # end c 2 ) ), ################ action definitions ################ Action['reset']( SetOption( 't0' = 0 ), SetOption( 't1' = 5 ), SetOption( 'y0' =0 ), SetOption( 'y1' = 15 ), SetOption( 's' = "-4.9*t^2+5*t+12" ), SetOption( 'v' = "-9.8*t+5" ), SetOption( 'a' = "-9.8" ), SetOption( 's_plot' = true ), SetOption( 'v_plot' = false ), SetOption( 'a_plot' = false ), SetOption( 's_color' = "blue" ), SetOption( 'v_color' = "red" ), SetOption( 'a_color' = "magenta" ), SetOption( 's_style' = "SOLID" ), SetOption( 'v_style' = "SOLID" ), SetOption( 'a_style' = "SOLID" ), SetOption( 'plot_cmds' = " " ), SetOption( 'expr' = "" ), SetOption( 't_value' = "" ), SetOption( 'eqn' = "" ), SetOption( 'results' = "" ), ########################## #SetOption( 't' = "t" ), #Removed - caused error on reset ########################## SetOption( 't2' = "t = " ), NULL ), Action['show_cmd']( Evaluate( 'plot_cmds' = 'LinMotionPlot( [s,s_plot,s_color,s_style], [v,v_plot,v_color,v_style], [a,a_plot,a_color,a_style], t, t0..t1, y0..y1, false )' ) ), Action['eval_expr']( Evaluate( 'results' = 'LinMotionEval( expr, s, v, a, t, t_value )' ) ), Action['solve_eqn']( Evaluate( 'results' = 'LinMotionSolve( eqn, s, v, a, t )' ) ) ): end use: Maplets:-Display(LinMotion);