Interpolacia presneho riesenia (presnej drahy)

Needs["VectorFieldPlots`"]

n=10;ListLinePlot[Table[{Cos[k 2Pi/n],Sin[k 2Pi/n]},{k,0,n}]]

Definuj rychlostne vektorove pole (casovo nezavisle)

vp1[x1_,x2_]=-1.0*x2
vp2[x1_,x2_]= 1.0*x1

VectorFieldPlot[{vp1[x,y],vp2[x,y]},{x,-1,1},{y,-1,1}]

Eulerova metoda pre vypocet drahy

Zaciatocny bod drahy a koncov2y cas

x[0] = 1.0; y[0]=0.0; T=2 Pi;

Parametre pre numericku metodu

nn=4000; tau = T/nn; 
For[n=0, n<nn, n++, 
x[n+1] = x[n] + tau * vp1[x[n],y[n]]; 
y[n+1] = y[n] + tau *vp2[ x[n],y[n]]
];
ListLinePlot[Table[{x[k],y[k]},{k,0,nn}]]

Numericke riesenie - koncovy bod drahy

x[nn]
y[nn]

Modifikovana Eulerova metoda

x[0] = 1.0; y[0]=0.0;nn=10; tau = 2 Pi/nn; 
For[n=0, n<nn, n++, 
xm=x[n]+tau/2*vp1[x[n],y[n]]; ym = y[n] + tau/2*vp2[x[n],y[n]];
x[n+1] = x[n] - tau * ym; y[n+1] = y[n] + tau * xm];
ListLinePlot[Table[{x[k],y[k]},{k,0,nn}]]

Linearne rychlostne vektorove pole

v1=0; v1x=0.0;v1y=-1.0;v2=0; v2x=1.0;v2y=0.0;

VectorFieldPlot[{v1+v1x*x+v1y*y,v2+v2x*x+v2y*y},{x,-1,1},{y,-1,1}]

Eulerova metoda pre 3 body trojuholnika

nn=1000; tau = 2 Pi/nn;

x[0] = 0.1; y[0]=0.1;
For[n=0, n<nn, n++, x[n+1] = x[n] + tau *( v1+v1x * x[n]+v1y*y[n]); y[n+1] = y[n] + tau *(v2+v2x*x[n]+ v2y*y[n])];

xx[0] = 0.1; yy[0]=0.08;
For[n=0, n<nn, n++, xx[n+1] = xx[n] + tau *( v1+v1x * xx[n]+v1y*yy[n]); yy[n+1] = yy[n] + tau *(v2+v2x*xx[n]+ v2y*yy[n])];

xxx[0] = 0.08; yyy[0]=0.1;
For[n=0, n<nn, n++, xxx[n+1] = xxx[n] + tau *(v1+ v1x  * xxx[n]+v1y*yyy[n]); yyy[n+1] = yyy[n] + tau *(v2+v2x*xxx[n]+ v2y*yyy[n])];

Animate[Graphics[Polygon[{{x[i],y[i]},{xx[i],yy[i]},{xxx[i],yyy[i]}}],Frame->True,PlotRange->{{-0.2,0.2},{-0.2,0.2}}],{i,0,nn,1}]

Animate[Graphics[Polygon[{{x[i],y[i]},{xx[i],yy[i]},{xxx[i],yyy[i]}}],Frame->True,PlotRange->{{0,1},{0,1}}],{i,0,nn,nn}]

i=100;Graphics[Polygon[{{x[i],y[i]},{xx[i],yy[i]},{xxx[i],yyy[i]}}],Frame->True]