Sandesh Bhat J R: 3 Year Undergraduate, IISER Pune
Sandesh Bhat J R: 3 Year Undergraduate, IISER Pune
rd
3 YearUndergraduate,IISERPune
BondiAccretionProblem:
C/CompiledinGCC|CompletelyOriginalCode
#include <stdio.h>
#include <math.h>
#define MBH 1
#define BN 0.00001
#define k 1
#define g 1.6666666667
double a(double n)
{
return sqrt(((g*k)*pow(n,(g-1.0)))/(MBH+((g*k*pow(n,(g-1)))/(g-1))));
}
double du(double u, double n, double r)
{
return (u*(((1.0-((2.0*MBH)/r)+(u*u))*(2*((a(n)*a(n))/r)))(MBH/(r*r))))/((u*u)-((1.0-((2.0*MBH)/r)+(u*u))*(a(n)*a(n))));
}
int main()
{
double u,n,d,as;
n=1000000;
for (u=0;u<1;u+=0.001)
{
d=du(u,n,10);
as=a(n);
printf("du=%lf a=%lf where %lf \n",d,as,u);
}
return 1;
}
RelaxationmethodonSimpleODE:
C/CompiledinGCC|CompletelyOriginalCode
#include <stdio.h>
#include <math.h>
#define NE 2
#define MP 500
#define BCa 1
double x[MP+1];
double y[NE][MP+1];
double E[NE][MP+1];
double S[(NE*MP)+1][NE*MP];
double SK[2*NE][NE];
double g(int n, int k)
{
if (n==0)
return ((y[1][k]+y[1][k-1])/2)+((x[k]+x[k-1])/2);
if (n==1)
return (x[k]+x[k-1])/2;
else return 0;
}
long solve(double *a,int n)
{
int i,j,k;
double t;
//now reducing to triangular matric
for(i=0;i<n;i++)
for(j=(i+1);j<n;j++)
{
if((a[i*(n+1)+i]==0) && (a[j*(n+1)+i]!=0))
0s in the diagonal elements
for(k=i;k<(n+1);k++)
{
t=a[i*(n+1)+k];
a[i*(n+1)+k]=a[j*(n+1)+k];
a[j*(n+1)+k]=t;
}
if((a[i*(n+1)+i]!=0) && (a[j*(n+1)+i]!=0))
for(k=(i+1);k<(n+1);k++)
a[(j*(n+1))+k]=a[(j*(n+1))+k](a[(i*(n+1))+k]*a[(j*(n+1))+i]/a[(i*(n+1))+i]);
}
//now solving the upper triangular matrix
for(i=(n-1);i>0;i--)
if(a[i*(n+1)+i]!=0)
for(j=(i-1);j>=0;j--)
a[(j*(n+1))+n]=a[(j*(n+1))+n](a[(i*(n+1))+n]*a[(j*(n+1))+i]/a[i*(n+1)+i]);
else
return 1;
for(i=0;i<n;i++)
a[i]=a[i*(n+1)+n]/a[i*(n+1)+i];
return 0;
}
double si(int k)
{
SK[0][0]=(-1);
SK[1][0]=((x[k-1]-x[k])/2);
SK[2][0]=1;
//condition to swapout
SK[3][0]=((x[k-1]-x[k])/2);
SK[0][1]=0;
SK[1][1]=-1;
SK[2][1]=0;
SK[3][1]=1;
}
int main()
{
//Set up Mesh points
int n,k,it;
x[0]=0;
x[MP-1]=1;
x[MP]=1;
const int N=NE*MP;
double d1[N*(N+1)];
//Allocating mesh values
for (k=1;k<MP;k++)
{
x[k]=x[k-1]+((x[MP-1]-x[0])/(MP-1));
}
for (k=0;k<MP;k++)
{
printf("%lf \n",x[k]);
}
//Guessing y
for (k=0;k<MP;k++)
for (n=0;n<NE;n++)
{
if (n==0)
y[n][k]=1;
else if (n==1)
y[n][k]=1;
}
//Taking all of y as 1
for (it=0;it<2;it++)
//Iteration loop
{
//Settin up E
//Interior
for (k=1;k<MP;k++)
for (n=0;n<NE;n++)
{
E[n][k]=(y[n][k]-y[n][k-1])-((x[k]-x[k-1])*(g(n,k)));
}
//Boundary
E[1][0]=y[1][0];
E[0][MP]=y[0][MP-1]-0.66666666;
printf("\n Values of E: \n");
for (n=0;n<NE;n++)
{
printf("Variable %d: \n",n+1);
for (k=0;k<MP+1;k++)
{
//Debug
//Solving matrix S
for (i=0;i<NE*MP;i++)
for (j=0;j<(NE*MP)+1;j++)
d1[i*((NE*MP)+1)+j]=S[j][i];
j=2;
j=solve(d1,NE*MP);
printf("\n Solutions: \n");
for(i=0;i<(NE*MP);i++)
printf("y(%d)=%f\n",i,d1[i]);
//Debug
//Debug
for (k=0;k<MP;k++)
{
printf("y(%d,%d)=%lf where x=%lf \n",n+1,k+1,y[n][k],x[k]);
}
//Debug
}
return 1;
}
ChristoffelSymbolsandGeodesic:
Mathematica|DerivedfromacodewrittenbyAravind
BondiCasebyRelaxation:
Mathematica|CompletelyOriginalCode
Clear[coord, metric, inversemetric, affine, r, \[Theta], \[Phi], t]
n = 3
coord = {r, \[Theta], \[Phi], t}
metric = {{1, 0, 0}, {0, r^2, 0}, {0, 0, (r^2)*((sin[\[Theta]])^2)}}
metric // MatrixForm
inversemetric = Simplify[Inverse[metric]]
inversemetric // MatrixForm
affine :=
affine = Simplify[
Table[(1/2)*
Sum[(inversemetric[[i, s]])*(D[metric[[s, j]], coord[[k]]] +
D[metric[[s, k]], coord[[j]]] D[metric[[j, k]], coord[[s]]]), {s, 1, n}], {i, 1, n}, {j, 1,
n}, {k, 1, n}]]
listaffine :=
Table[If[UnsameQ[affine[[i, j, k]],
QCDEoM:
Mathematica|CompletelyOriginalCode
dipp[T_]:=pp'[T]/(pp[T]+[T]);
die[T_]:='[T]/(pp[T]+[T]);
eq1:=(u'/u)+(die[T]*T')+(2/r)
eq2:=(u*u')+(dipp[T]*T'*(1+(u^2)-(2/r)))+(1/(r^2))
Solve[{eq10,eq20},{u',T'}]
{{u-((u (-4 pp[T]+2 r pp[T]+2 r u2 pp[T]-[T]))/(r (-2 pp[T]+r pp[T]+r u2 pp[T]-r u2 [T]))),T((-1+2 r u2)
(pp[T]+[T]))/(r (-2 pp[T]+r pp[T]+r u2 pp[T]-r u2 [T]))}}
1/2 (y[1][-1+k]+y[1][k])
1/2 (y[2][-1+k]+y[2][k])
r=ro-(s*t);
u=((y[1][k]+y[1][k-1])/2)
T=((y[2][k]+y[2][k-1])/2)
s=((y[3][k]+y[3][k-1])/2)
t=((x[k]+x[k-1])/2)
-((u (-4 pp[T]+2 r pp[T]+2 r u2 pp[T]-[T]))/(r (-2 pp[T]+r pp[T]+r u2 pp[T]-r u2 [T])))
((-1+2 r u2) (pp[T]+[T]))/(r (-2 pp[T]+r pp[T]+r u2 pp[T]-r u2 [T]))
1/2 (y[1][-1+k]+y[1][k])
1/2 (y[2][-1+k]+y[2][k])
1/2 (y[3][-1+k]+y[3][k])
1/2 (x[-1+k]+x[k])
-((y[1][-1+k]+y[1][k]) (-4 pp[1/2 (y[2][-1+k]+y[2][k])]+2 (ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) pp[1/2 (y[2][1+k]+y[2][k])]+1/2 (y[1][-1+k]+y[1][k])2
(ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) pp[1/2 (y[2][-1+k]+y[2][k])]-
[1/2 (y[2][-1+k]+y[2][k])]))/(2 (ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) (-2 pp[1/2 (y[2][-1+k]+y[2][k])]+(ro-1/4 (x[-1+k]+x[k]) (y[3][1+k]+y[3][k])) pp[1/2 (y[2][-1+k]+y[2][k])]+1/4 (y[1][-1+k]+y[1][k])2
pp
(ro-x[MP] y[3][MP]) [y[2][MP]]))
((pp[y[2][MP]]+[y[2][MP]]) (-1+2 y[1][MP]2 (ro-x[MP] y[3][MP])))/((ro-x[MP] y[3][MP]) (-2
pp[y[2][MP]]+(ro-x[MP] y[3][MP]) pp[y[2][MP]]+y[1][MP]2 (ro-x[MP] y[3][MP]) pp[y[2][MP]]-y[1][MP]2 (ro-x[MP]
y[3][MP]) [y[2][MP]]))
QCDcasebyRelaxation:
Mathematica|CompletelyOriginalCode
<<qcddata;
pp=Interpolation[pplst0];
=Interpolation[lst0];
=Interpolation[l];
4
Plot[pp[T]/T^4,{T,0.001,1.0},AxesLabel{"T","p/T "}, AxesOrigin{0,0}]
4
p
T4
4
0.2
0.4
0.6
0.8
1.0
0.2
0.4
0.6
0.8
1.0
T4
14
12
10
8
6
4
2
(* Initial conditions *)
Clear[e,g,y,x,dy,n,k,SM,IE,BE]
NE=3; (* Number of Equations *)
MP=100; (* Number of Mesh Points, including the inital and final point *)
Array[dy,{NE,MP}];
(* Setting up mesh points *)
x[1]=0;
x[MP]=1;
Table[x[k]=x[k-1]+((x[MP]-x[1])/(MP-1)),{k,2,MP}];
(* Putting expressions *)
ro=10;
g[1][k_]:=-((y[1][-1+k]+y[1][k]) (-4 pp[1/2 (y[2][-1+k]+y[2][k])]+2 (ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) pp[1/2
(y[2][-1+k]+y[2][k])]+1/2 (y[1][-1+k]+y[1][k])2
(ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) pp[1/2 (y[2][1+k]+y[2][k])]-[1/2 (y[2][-1+k]+y[2][k])]))/(2 (ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) (-2 pp[1/2 (y[2][-1+k]+y[2][k])]+(ro-1/4 (x[1+k]+x[k]) (y[3][-1+k]+y[3][k])) pp[1/2 (y[2][-1+k]+y[2][k])]+1/4 (y[1][-1+k]+y[1][k])2
[1/2 (y[2][-1+k]+y[2][k])]-1/4 (y[1][-1+k]+y[1][k])2
1+k]+y[3][k])) pp
1+k]+y[3][k])) [1/2 (y[2][-1+k]+y[2][k])]));
g[2][k_]:=((pp[1/2 (y[2][-1+k]+y[2][k])]+[1/2 (y[2][-1+k]+y[2][k])]) (-1+1/2 (y[1][1+k]+y[1][k])2 (ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k]))))/((ro-1/4 (x[-1+k]+x[k]) (y[3][1+k]+y[3][k])) (-2 pp[1/2 (y[2][-1+k]+y[2][k])]+(ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) pp[1/2 (y[2][-1+k]+y[2][k])]+1/4
(y[1][-1+k]+y[1][k])2
(ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) pp[1/2 (y[2][-1+k]+y[2][k])]-1/4 (y[1][1+k]+y[1][k])2
(ro-1/4 (x[-1+k]+x[k]) (y[3][-1+k]+y[3][k])) [1/2 (y[2][-1+k]+y[2][k])]));
g[3][k_]:=0;
(* Interior conditions *)
e[n_][k_]:=y[n][k]-y[n][k-1]-(y[3][k]*(x[k-1]-x[k])*(g[n][k]));
(* Boundary conditions *)
B[1]=y[2][MP]-0.8;
B[2]= (-2 pp[y[2][MP]]+(ro-x[MP] y[3][MP]) pp[y[2][MP]]+y[1][MP]2 (ro-x[MP] y[3][MP]) pp[y[2][MP]]-y[1][MP]2
(ro-x[MP] y[3][MP]) [y[2][MP]]);
B[3]= (-4 pp[y[2][MP]]+2 (ro-x[MP] y[3][MP]) pp[y[2][MP]]+2 y[1][MP]2 (ro-x[MP] y[3][MP]) pp[y[2][MP]][y[2][MP]]);
ind[1]=MP;
ind[2]=MP;
ind[3]=MP;
(* Finding S interior *)
IE=Table[Sum[D[e[n][k],y[ja][k-1]]*dy[ja][k1],{ja,1,3}]+Sum[D[e[n][k],y[jb][k]]*dy[jb][k],{jb,1,3}]-(e[n][k]),{n,1,NE},{k,2,MP}];
(* Finding S Boundary *)
BE=Table[Sum[D[B[n],y[bj][ind[n]]]*dy[bj][ind[n]],{bj,1,3}] -(B[n]),{n,1,NE}];
(* Guessing y *)
SM=Flatten[Join[IE,BE]];
Table[y[1][k]=0.4,{k,1,MP}];
Table[y[2][k]=0.9,{k,1,MP}];
Table[y[3][k]=6.98,{k,1,MP}];
(* Solving for dy - Need to manually iterate by evaluating repeatedly *)
ssol=Solve[SM,Flatten[Table[dy[n][k],{n,1,NE},{k,1,MP}]]];Table[y[n][k]=y[n][k]+(dy[n][k]/.s
sol),{n,1,NE},{k,1,MP}]//N;
Average_Deviation:(Sum[B[n],{n,1,NE}]+Sum[e[n][k],{n,1,NE},{k,2,MP}])/(NE*MP)
Average_Deviation:{-2.4548310-15}
(* Displaying final results *)
Average_Deviation:(Sum[B[n],{n,1,NE}]+Sum[e[n][k],{n,1,NE},{k,2,MP}])/(NE*MP)
outy:=Table[{ToString[y[n,k]],"=",y[n][k]},{n,1,NE},{k,10,MP}]
TableForm[Partition[DeleteCases[Flatten[outy],Null],3],TableSpacing {2,2}]
Clear[ulst,tlst];
ulst={};Do[ulst=Append[ulst,{Flatten[{(ro-(y[3][k]*x[k])),y[1][k]}]}],{k,1,MP}];
ListPlot[ulst,PlotRangeAll,AxesLabel{"r","u"}, AxesOrigin{0,0}]
tlst={};Do[tlst=Append[tlst,{Flatten[{(ro-(y[3][k]*x[k])),y[2][k]}]}],{k,1,MP}];
ListPlot[tlst,PlotRangeAll,AxesLabel{"r","T"}, AxesOrigin{0,0}]
Average_Deviation:{-2.4548310-15}
< Results are omitted here as they are lengthy >
u
0.4
0.3
0.2
0.1
10
10
T
0.8
0.6
0.4
0.2
1Doscillator:
Mathematica|CompletelyOriginalCode
(*
Problem 1: 1-d oscillator
1.Phase space diagram for different Initial Values of x,p
2.Time period
*)
m=1
V=-(x[t]^2)/2+(x[t]^4)/4
H=(p[t]^2)/(2*m)+V
1
-(1/2) x[t]2+x[t]4/4
p[t]2/2-x[t]2/2+x[t]4/4
(*
Noting points of Equilibrium
*)
Solve[{D[V,x[t]]0},x[t]]
{{x[t]-1},{x[t]0},{x[t]1}}
(*
Equilibrium is at 0, 1. We check the behaviour of the particle around these ranges
*)
(* Solving around x=0 *)
s1=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]0,p[0]0},{x,p},{t,0,20}]
s2=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]0,p[0]0.01},{x,p},{t,0,20}]
s3=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]0,p[0]0.2},{x,p},{t,0,20}]
s4=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]0,p[0]0.5},{x,p},{t,0,20}]
s5=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]0,p[0]1},{x,p},{t,0,20}]
s6=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]0,p[0]3},{x,p},{t,0,20}]
FindRoot[(x[t]x[0])/.s2,{t,12}]
Plot[Evaluate[p[t]/.{s1,s2,s3,s4,s5,s6}],{t,0,12},PlotStyle->Automatic]
Plot[Evaluate[{x[t]}/.{s1,s2,s3,s4,s5,s6}],{t,0,12},PlotStyle->Automatic]
ParametricPlot[Evaluate[{x[t],p[t]}/.{s1,s2,s3,s4,s5,s6}],{t,0,20}]
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{t12.676}
3
2
1
10
12
10
12
-1
-2
-3
-1
-2
-2
-1
-1
-2
-3
(*
Turns out to be an unstable equilibrium
Now, we can see that around 1, we have stable equilibrium.
I have solved for +1; and it is clear that we get symmetric result for -1 too.
*)
l1=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]0},{x,p},{t,0,20}]
l2=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]0.01},{x,p},{t,0,20}]
l3=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]0.2},{x,p},{t,0,20}]
l4=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]0.5},{x,p},{t,0,20}]
l5=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]1},{x,p},{t,0,20}]
l6=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]3},{x,p},{t,0,20}]
Plot[Evaluate[p[t]/.{l1,l2,l3,l4,l5,l6}],{t,0,12},PlotStyle->Automatic]
Plot[Evaluate[{x[t]}/.{l1,l2,l3,l4,l5,l6}],{t,0,12},PlotStyle->Automatic]
ParametricPlot[Evaluate[{x[t],p[t]}/.{l1,l2,l3,l4,l5,l6}],{t,0,20}]
FindRoot[(x[t]x[0])/.l2,{t,5}]
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
1.5
1.0
0.5
10
12
10
12
- 0.5
- 1.0
- 1.5
2.0
1.5
1.0
0.5
- 0.5
- 1.0
1.5
1.0
0.5
- 1.0
- 0.5
0.5
1.0
1.5
2.0
- 0.5
- 1.0
- 1.5
{t4.44304}
(* The last case is the case of high momentum where the whole setup acts as a 1 oscillator*)
k1=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]0,p[0]30},{x,p},{t,0,20}]
k2=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]30},{x,p},{t,0,20}]
k3=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]30},{x,p},{t,0,20}]
k4=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]50},{x,p},{t,0,20}]
k5=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]10},{x,p},{t,0,20}]
k6=NDSolve[{x'[t]D[H,p[t]],p'[t]-(D[H,x[t]]),x[0]1,p[0]30},{x,p},{t,0,20}]
Plot[Evaluate[p[t]/.{k1,k2,k3,k4,k5,k6}],{t,0,12},PlotStyle->Automatic]
Plot[Evaluate[{x[t]}/.{k1,k2,k3,k4,k5,k6}],{t,0,12},PlotStyle->Automatic]
ParametricPlot[Evaluate[{x[t],p[t]}/.{k1,k2,k3,k4,k5,k6}],{t,0,20}]
FindRoot[(x[t]x[0])/.k1,{t,5}]
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{xInterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
40
20
10
12
10
12
- 20
- 40
-5
40
20
-5
- 20
- 40
{t5.15091}
(* A final phase space plot *)
ParametricPlot[Evaluate[{x[t],p[t]}/.{s1,s2,s3,s4,s5,s6,l1,l2,l3,l4,l5,l6,k1,k2,k3,k4,k5,k6}],{t,0,2
0}]
RotatingPendulum:
Mathematica|CompletelyOriginalCode
(*
Problem 2: Rotating Pendulum
Pendulum constrained in a circle rotating at ang. velocity
1.Check for 2 cases
*)
(* Case 1 *)
m=1;l=1;g=9.8;=2;
[t]'p[t]/(m*(l^2))
p[t]'-m*g*l*sin[[t]]*(1-((^2)*l*cos[[t]]/g))
s=NDSolve[{'[t]p[t]/(m*(l^2)),p'[t]-m*g*l*Sin[[t]]*(1((^2)*l*Cos[[t]]/g)),[0]0,p[0]1},{,p},{t,0,10}]
Plot[Evaluate[{p[t]}/.s],{t,0,10},PlotStyle->Automatic]
Plot[Evaluate[{[t]}/.s],{t,0,10},PlotStyle->Automatic]
ParametricPlot[Evaluate[{[t],p[t]}/.s],{t,0,10}]
ParametricPlot[Evaluate[{Sin[[t]],-Cos[[t]]}/.s],{t,0,2},AxesOrigin{0,0}]
[t]p[t]
p[t]-9.8 (1-0.408163 cos[[t]]) sin[[t]]
{{InterpolatingFunction[{{0.,10.}},<>],pInterpolatingFunction[{{0.,10.}},<>]}}
1.0
0.5
10
10
- 0.5
- 1.0
0.4
0.2
- 0.2
- 0.4
1.0
0.5
- 0.4
- 0.2
0.2
0.4
- 0.5
- 1.0
- 0.4
- 0.2
0.2
- 0.2
- 0.4
- 0.6
- 0.8
- 1.0
0.4
(* Case 2 *)
m=1;l=1;g=9.8;=4;
[t]'p[t]/(m*(l^2))
p[t]'-m*g*l*sin[[t]]*(1-((^2)*l*cos[[t]]/g))
s1=NDSolve[{'[t]p[t]/(m*(l^2)),p'[t]-m*g*l*Sin[[t]]*(1-((^2)*l*Cos[[t]]/g)),[0]1,p[0]0.1},{,p},{t,0,20}]
s2=NDSolve[{'[t]p[t]/(m*(l^2)),p'[t]-m*g*l*Sin[[t]]*(1((^2)*l*Cos[[t]]/g)),[0]1,p[0]1},{,p},{t,0,20}]
s3=NDSolve[{'[t]p[t]/(m*(l^2)),p'[t]-m*g*l*Sin[[t]]*(1((^2)*l*Cos[[t]]/g)),[0]0.01,p[0]0},{,p},{t,0,20}]
s4=NDSolve[{'[t]p[t]/(m*(l^2)),p'[t]-m*g*l*Sin[[t]]*(1-((^2)*l*Cos[[t]]/g)),[0]0.01,p[0]0},{,p},{t,0,20}]
Plot[Evaluate[{p[t]}/.{s1,s2,s3,s4}],{t,0,20},PlotStyle->Automatic]
Plot[Evaluate[{[t]}/.{s1,s2,s3,s4}],{t,0,20},PlotStyle->Automatic]
ParametricPlot[Evaluate[{[t],p[t]}/.{s1,s2,s3,s4}],{t,0,20},AxesOrigin{0,0}]
ParametricPlot[Evaluate[{Sin[[t]],-Cos[[t]]}/.{s1,s2,s3,s4}],{t,0,20},AxesOrigin{0,0}]
[t]p[t]
p[t]-9.8 (1-1.63265 cos[[t]]) sin[[t]]
{{InterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{InterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{InterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
{{InterpolatingFunction[{{0.,20.}},<>],pInterpolatingFunction[{{0.,20.}},<>]}}
1.5
1.0
0.5
10
15
20
10
15
20
- 0.5
- 1.0
- 1.5
1.0
0.5
- 0.5
- 1.0
1.5
1.0
0.5
- 1.0
- 0.5
0.5
1.0
- 0.5
- 1.0
- 1.5
- 1.0
- 0.5
0.5
- 0.2
- 0.4
- 0.6
- 0.8
- 1.0
1.0
10
-5
-5
- 10
Plot[Evaluate[(((p[t]^2)/2)-((x[t]^2)/2)+((x[t]^4)/4))/.l5],{t,0,12},AxesOrigin{0,0}]
Plot[((p[t]^2)/2)/.l5,{t,0,12}]
Plot[((-(x[t]^2)/2)+((x[t]^4)/4))/.l5,{t,0,12}]
0.25
0.20
0.15
0.10
0.05
10
12
10
12
0.5
0.4
0.3
0.2
0.1
0.2
0.1
10
12
- 0.1
- 0.2
CentralForceSchwarzschildlikepotential:
Mathematica|CompletelyOriginalCode
(*
Problem 3: Central force motion
1.Bounded motion
2.Unbounded motion
*)
Clear[m,k,l,V,H,r,t]
m=1;k=1;l=1;
V=-(k/r[t])+((l^2)/(2*m*(r[t]^2)))
H=(p[t]^2)/(2*m)+V
1/(2 r[t]2)-1/r[t]
p[t]2/2+1/(2 r[t]2)-1/r[t]
(* Checking for equilibriums *)
Solve[D[V,r[t]]0,r[t]]
{{r[t]1}}
(* Bounded motion around 1 *)
s1=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]0.1},{r,p},{t,0,100}]
s2=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]0.2},{r,p},{t,0,100}]
s3=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]0.3},{r,p},{t,0,100}]
s4=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]0.4},{r,p},{t,0,100}]
s5=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]0.8},{r,p},{t,0,100}]
s6=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]0.9},{r,p},{t,0,100}]
s7=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]1.2},{r,p},{t,0,100}]
Plot[Evaluate[{p[t]}/.{s1,s2,s3,s4,s5,s6,s7}],{t,0,100},PlotStyle->Automatic]
Plot[Evaluate[{r[t]}/.{s1,s2,s3,s4,s5,s6,s7}],{t,0,100},PlotStyle->Automatic]
ParametricPlot[Evaluate[{r[t],p[t]}/.{s1,s2,s3,s4,s5,s6,s7}],{t,0,100}]
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
1.0
0.5
20
40
60
80
100
80
100
- 0.5
20
15
10
20
40
60
1.0
0.5
- 0.5
10
15
20
(* The last case p>1; escapes the potential well. Thus it is an example of unbounded motion.
For x[0]=0; p<1; motion is bounded. *)
(* Unbounded motion: more of them *)
u1=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]1.1},{r,p},{t,0,100}]
u2=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]-1,p[0]1.2},{r,p},{t,0,100}]
u3=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]2,p[0]1.3},{r,p},{t,0,100}]
u4=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]-2,p[0]1.4},{r,p},{t,0,100}]
u5=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]1,p[0]-1.1},{r,p},{t,0,100}]
u6=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]-1,p[0]-1.2},{r,p},{t,0,100}]
u7=NDSolve[{r'[t]D[H,p[t]],p'[t]-(D[H,r[t]]),r[0]-1,p[0]-1.3},{r,p},{t,0,100}]
Plot[Evaluate[{p[t]}/.{u1,u2,u3,u4,u5,u6,u7}],{t,0,100},PlotStyle->Automatic]
Plot[Evaluate[{r[t]}/.{u1,u2,u3,u4,u5,u6,u7}],{t,0,100},PlotStyle->Automatic]
ParametricPlot[Evaluate[{r[t],p[t]}/.{u1,u2,u3,u4,u5,u6,u7}],{t,0,100}]
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
{{rInterpolatingFunction[{{0.,100.}},<>],pInterpolatingFunction[{{0.,100.}},<>]}}
1.0
0.5
20
40
60
80
100
20
40
60
80
100
- 0.5
- 1.0
- 1.5
- 2.0
100
50
- 50
- 100
- 150
- 200
- 200
- 150
- 100
- 50
50
100
DoublePendulum:
Mathematica|CompletelyOriginalCode
(*
Problem 4: Double Pendulum:
This has 3 cases to be solved. The equation of motion has already been specified in differential
form.
*)
(* Init *)
Clear[1,2,p1,p2,m1,m2,l1,l2,g,t,C1,C2]
m1=1;m2=1;l1=1;l2=1;g=9.8;
C1=p1[t]*p2[t]*Sin[1[t]-2[t]]/(l1*l2*(m1+(m2*(Sin[1[t]-2[t]]^2))))
C2=((((l2^2)*m2*(p1[t]^2))+((l1^2)*(m1+m2)*(p2[t]^2))-(l1*l2*m2*p1[t]*p2[t]*Cos[1[t]2[t]]))/(2*(l1^2)*(l2^2)*(m1+(m2*(Sin[1[t]-2[t]]^2)))))*Sin[(2*(1[t]-2[t]))]
1'[t]==((l2*p1[t])-(l1*p2[t]*Cos[1[t]-2[t]]))/((l1^2)*l2*(m1+(m2*(Sin[1[t]-2[t]]^2))))
2'[t](l1(m1+m2)p2[t]-l2*m2*p1[t]*Cos[1[t]-2[t]])/(l1*(l2^2)*m2*(m1+(m2*((Sin[1[t]2[t]])^2))))
p1'[t]-(m1+m2)*g*l1*Sin[1[t]]-C1+C2
p2'[t]-m2*g*l2*Sin[2[t]]+C1-C2
(p1[t] p2[t] Sin[1[t]-2[t]])/(1+Sin[1[t]-2[t]]2)
((p1[t]2-Cos[1[t]-2[t]] p1[t] p2[t]+2 p2[t]2) Sin[2 (1[t]-2[t])])/(2 (1+Sin[1[t]-2[t]]2))
1[t](p1[t]-Cos[1[t]-2[t]] p2[t])/(1+Sin[1[t]-2[t]]2)
2[t](-Cos[1[t]-2[t]] p1[t]+2 p2[t])/(1+Sin[1[t]-2[t]]2)
p1[t]-19.6 Sin[1[t]]-(p1[t] p2[t] Sin[1[t]-2[t]])/(1+Sin[1[t]-2[t]]2)+((p1[t]2-Cos[1[t]-2[t]] p1[t] p2[t]+2
p2[t]2) Sin[2 (1[t]-2[t])])/(2 (1+Sin[1[t]-2[t]]2))
p2[t](p1[t] p2[t] Sin[1[t]-2[t]])/(1+Sin[1[t]-2[t]]2)-((p1[t]2-Cos[1[t]-2[t]] p1[t] p2[t]+2 p2[t]2) Sin[2
(1[t]-2[t])])/(2 (1+Sin[1[t]-2[t]]2))-9.8 Sin[2[t]]
(* Case 1 *)
s=NDSolve[{1'[t]==((l2*p1[t])-(l1*p2[t]*Cos[1[t]-2[t]]))/((l1^2)*l2*(m1+(m2*(Sin[1[t]2[t]]^2)))),2'[t](l1(m1+m2)p2[t]-l2*m2*p1[t]*Cos[1[t]2[t]])/(l1*(l2^2)*m2*(m1+(m2*((Sin[1[t]-2[t]])^2)))),p1'[t]-(m1+m2)*g*l1*Sin[1[t]]C1+C2,p2'[t]-m2*g*l2*Sin[2[t]]+C1-C2,1[0]3.14,2[0]3.14,p1[0]20,p2[0]50},{1,2,p1,p2},{t,0,1}]
Plot[Evaluate[{p1[t]}/.s],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{1[t]}/.s],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{p2[t]}/.s],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{2[t]}/.s],{t,0,1},PlotStyle->Automatic]
ParametricPlot[Evaluate[{(Sin[1[t]]+Sin[2[t]]),-(Cos[1[t]]+Cos[2[t]])}/.s],{t,0,1}]
ParametricPlot[Evaluate[{Sin[1[t]],-(Cos[1[t]])}/.s],{t,0,1}]
{{1InterpolatingFunction[{{0.,1.}},<>],2InterpolatingFunction[{{0.,1.}},<>],p1Interpol
atingFunction[{{0.,1.}},<>],p2InterpolatingFunction[{{0.,1.}},<>]}}
60
50
40
30
0.2
0.4
0.6
0.8
1.0
16
14
12
10
8
6
0.2
0.4
0.6
0.8
1.0
- 50
- 60
- 70
- 80
- 20
- 40
- 60
- 80
0.2
0.4
0.6
0.8
1.0
0.2
0.4
0.6
0.8
1.0
-2
-1
0.5
1.0
-1
-2
1.0
0.5
- 1.0
- 0.5
- 0.5
- 1.0
(* Case 2 *)
l=NDSolve[{1'[t]==((l2*p1[t])-(l1*p2[t]*Cos[1[t]-2[t]]))/((l1^2)*l2*(m1+(m2*(Sin[1[t]2[t]]^2)))),2'[t](l1(m1+m2)p2[t]-l2*m2*p1[t]*Cos[1[t]2[t]])/(l1*(l2^2)*m2*(m1+(m2*((Sin[1[t]-2[t]])^2)))),p1'[t]-(m1+m2)*g*l1*Sin[1[t]]C1+C2,p2'[t]-m2*g*l2*Sin[2[t]]+C1-C2,1[0]3.14,2[0]3.14,p1[0]10,p2[0]8.89},{1,2,p1,p2},{t,0,1}]
Plot[Evaluate[{p1[t]}/.l],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{1[t]}/.l],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{p2[t]}/.l],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{2[t]}/.l],{t,0,1},PlotStyle->Automatic]
ParametricPlot[Evaluate[{(Sin[1[t]]+Sin[2[t]]),-(Cos[1[t]]+Cos[2[t]])}/.l],{t,0,1}]
ParametricPlot[Evaluate[{Sin[1[t]],-(Cos[1[t]])}/.l],{t,0,1}]
{{1InterpolatingFunction[{{0.,1.}},<>],2InterpolatingFunction[{{0.,1.}},<>],p1Interpol
atingFunction[{{0.,1.}},<>],p2InterpolatingFunction[{{0.,1.}},<>]}}
24
22
20
18
16
14
12
0.2
0.4
0.6
0.8
1.0
0.2
0.4
0.6
0.8
1.0
0.6
0.8
1.0
12
10
- 10
- 12
- 14
- 16
- 18
0.2
0.4
0.2
0.4
0.6
0.8
1.0
-5
- 10
- 15
2.0
1.5
1.0
0.5
- 1.5
- 1.0
- 0.5
0.5
1.0
1.5
- 0.5
1.0
0.5
- 1.0
- 0.5
0.5
- 0.5
- 1.0
1.0
(* Case 3 *)
n=NDSolve[{1'[t]==((l2*p1[t])-(l1*p2[t]*Cos[1[t]-2[t]]))/((l1^2)*l2*(m1+(m2*(Sin[1[t]2[t]]^2)))),2'[t](l1(m1+m2)p2[t]-l2*m2*p1[t]*Cos[1[t]2[t]])/(l1*(l2^2)*m2*(m1+(m2*((Sin[1[t]-2[t]])^2)))),p1'[t]-(m1+m2)*g*l1*Sin[1[t]]C1+C2,p2'[t]-m2*g*l2*Sin[2[t]]+C1C2,1[0](22/7),2[0](22/7),p1[0]0,p2[0]0},{1,2,p1,p2},{t,0,1}]
Plot[Evaluate[{p1[t]}/.n],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{1[t]}/.n],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{p2[t]}/.n],{t,0,1},PlotStyle->Automatic]
Plot[Evaluate[{2[t]}/.n],{t,0,1},PlotStyle->Automatic]
ParametricPlot[Evaluate[{(Sin[1[t]]+Sin[2[t]]),-(Cos[1[t]]+Cos[2[t]])}/.n],{t,0,1}]
ParametricPlot[Evaluate[{Sin[1[t]],-(Cos[1[t]])}/.n],{t,0,1}]
{{1InterpolatingFunction[{{0.,1.}},<>],2InterpolatingFunction[{{0.,1.}},<>],p1Interpol
atingFunction[{{0.,1.}},<>],p2InterpolatingFunction[{{0.,1.}},<>]}}
0.14
0.12
0.10
0.08
0.06
0.04
0.02
0.2
0.4
0.6
0.8
1.0
0.6
0.8
1.0
3.175
3.170
3.165
3.160
3.155
3.150
0.2
0.4
0.005
0.2
0.4
0.6
0.8
1.0
0.6
0.8
1.0
- 0.005
- 0.010
- 0.015
3.140
3.135
3.130
3.125
3.120
3.115
0.2
0.4
2.0000
1.9999
1.9998
1.9997
- 0.0045
- 0.035
- 0.030
- 0.0040
- 0.025
- 0.0035
- 0.020
- 0.015
- 0.0030
- 0.010
- 0.0025
- 0.005
- 0.0020
0.000