kill(all)$

appendix :solve vector differential equation , version 1.0
(example : x_max ? flat earth.'ideal')
peter.vlasschaert@gmail.com,19/06/2018

load(lrats)$

syntax : lratsubst([,,],eq) found in package above.
l=list , rat = rational ,subst = substitute

p1:m*'diff(vec(V),t) = m*vec(G);

p2:vec(V)=[v_x,v_y];
p3:vec(G)=[g_x,g_y];

p4:lratsubst([p2,p3],p1);

p5:ev(p4,diff);

rem : first part gives vector = [0,0]
? Why : {v_x,v_y} are symbol , like a constant,differentation const=0

How to solve : v_x = v_x(t),v_y=v_y(t)  ?
=> depends 'command'

depends([v_x,v_y],t);

p6:ev(p4,diff);

seperation :' two' differential equations.one x,one y

p7:  lhs(p6)[1] = rhs(p6)[1];
p7a:lhs(p6)[2] = rhs(p6)[2];

simplify : ?  'removes'

1e)  nothing :solution

p8:ratexpand(p7);

2e)  method   : solution

p9:lhs(p8)-rhs(p8) = 0;

p9a:factor(p9);

p9b:part(p9a,1,2) = rhs(p9a);

rem:simplification {p7,p7a}

3e) method: with solve (easy method to remove 'm' both sides)

p10:solve(p7,diff(v_x,t));

p10a:p10[1];

simplification :  two differential equations ,x,y

p11:  solve(p7,diff(v_x,t))[1];
p11a:solve(p7a,diff(v_y,t))[1];

solve :  first  ODE
===============

p12:ode2(p11, v_x, t);

t=0   : v_x =v_x0  ?  find  %c

p12a:lratsubst([t=0,v_x=v_x0],p12);

p12b:lratsubst([rhs(p12a)=lhs(p12a)],p12);

solve :  second  ODE
==================

p13:ode2(p11a,v_y, t);

t=0: v_y=v_y0 ? find %c

p13a:lratsubst([t=0,v_y=v_y0],p13);

p13b:lratsubst([rhs(p13a)=lhs(p13a)],p13);

solve : x(t),y(t)

p14:lratsubst([v_x='diff(x,t),v_y='diff(y,t)],p2);

p14a :rhs(p14)=[rhs(p12b),rhs(p13b)];

rem : see above  'procedure'

p15:  lhs(p14a)[1] = rhs(p14a)[1];
p15a:lhs(p14a)[2] = rhs(p14a)[2];

solve : system of ODEs
====================

first:         ODE
second : ODE

p16:ode2(p15,x,t);
p16a:ode2(p15a,y,t);

first          :ODE ,t=0 ,x=x_0
second    :ODE,t=0, y=y_0

p17::lratsubst([t=0,x=x_0],p16);
p17a::lratsubst([t=0,y=y_0],p16a);

p18:lratsubst([rhs(p17)=lhs(p17)],p16);
p18a:lratsubst([rhs(p17a)=lhs(p17a)],p16a);

p19:expand(p18);
p19a:expand(p18a);

gravitation field :earth  :  'g'  value.

p20:lratsubst([g_x=0,g_y=-g],p19);
p20a:lratsubst([g_x=0,g_y=-g],p19a)$
p20b:ratexpand(p20a);

hit :ground. (y=0,suppose x_0=0,y_0=0)

p21:lratsubst([y=0,y_0=0,t=t_final],p20b);

p21a:solve(p21,t_final);

p21b:p21a[1];

find :Max distance projectile can reach. (suppose: x_0=0)

1e) we need values : v_x0,v_y0

v_x0 : v0*cos(θ);
v_y0: v0*sin(θ);
x_0 :0;
t:rhs(p21b);

2e) values in 'p20'  ,don't for get  'ev' =evaluation

p22:ev(p20);

p22a:ev(p22);

p22b:trigreduce(p22a);

rem : sin(2*θ) = 2*cos(θ)*sin(θ)

3e)  Max value : distance 'x' (on the ground) = x_max
        =>  dx/dθ = 0

p23:'diff(x,θ) = diff(rhs(p22b),θ);

p23a : rhs(p23) =0;

p23b :solve(p23a,θ);

4e)  result 'p23b'  into 'p22b'  =>  x=x_max.

p24:lratsubst([p23b[1],x=x_max],p22b);

All calculation :     -1 =< sin(2*θ)  =< 1,direct found ,sin(2*θ) = 1
into 'p22b'
why : definition sin,cos for angle.

p25:lratsubst([x=x_max,sin(2*θ)=1],p22b);

rem:

We can reach  a target  at distance : x <  =v0^2/g , see above 'less than x_max'
=================================================================

with : launch angle θ => satisfy 'p26'
------------------------------------------------------

p26:solve(p22b,sin(2*θ))[1];

we can 'hit target'  =>  two trajectories that work
========================================
1e)   0    < θ < π/4, ( first quadrant)
2e)  π/4 <  θ < π/2,(second quadrant)
why : same value sign of sin , θ = launch angle.

----------------------------------------------------------------------------------------------------------------------------