Two and three body problems.
function f2body (x,y,m1,m2) y=f(x,y) for the differential equations
function test2body (y1,m1=1,m2=1,n=100,tmax=360,fixed=0,h=1) 2-body demo Intial y is a row vector with two positions and two speed vectors in the form [x1,y1,x2,y2,vx1,vy1,vx2,vy2]. m1 and m2 are the masses of the two bodies. For slower animation increase h. For more accuracy increase n. The simulation runs until one body leaves the definition area (unless fixed is true), or tmax is reached. >fixed fixes the display at the first mass, which is positioned in (0,0).
function f3body (x,y,m1,m2,m3) y=f(x,y) for the differential equations
function test3body (y1,m1=1,m2=1,m3=1,n=100,fixed=0,tmax=360,h=1) 3-body demo Works like test2body, but takes three positions and speed vectors, and three masses.
function setplanets Set the planets and initial vectors with the mouse. 3-body which sets the positions with the mouse.