--This example simulates a projectile with air friction proportional to its velocity. Upper case variables are {x,y} vectors. See example "falling" for an example in 1 dimension.

-- initial conditions
init = V:={2,50},  -- velocity (mostly upward)
       P:={0,0},   -- position
       t:=0

stepto(stop) = init when stop=0,
             (V:=V+A*dt,
              P:=P+V*dt,
              t:=t+dt) while t<stop

A=F/m
Fgravity = {0,-m*g}
Fdrag = -k*V
F=Fgravity+Fdrag

g=9.8       -- accelleration due to gravity
k=0         -- friction coefficient
m=300       -- mass of object
dt=.1       -- time step for simulation

Position(t1) = stepto(t1),P

-- parametric plot of position for t=0 to 10
-- {x,y} plot runs X from 0 to 1. Create new variable "tn" that runs 0 to tmax.
tmax=10
tn=X*tmax  

Ymin=0; Ymax=130;  Xmin=0; Xmax=20

plot Position(tn)  -- no friction

label k:=20:;      -- with friction
plot Position(tn)
