MSC Ivsem
MSC Ivsem
dimension x(200)
open(3,file='multigen')
write(*,*)'no. of random numbers'
read(*,*)n
read(*,*)a,m
read(*,*) seed
x(1)=seed/m
do 150 i=1,n,1
mx=x(i)
x(i)=x(i)-mx
write(*,*)x(i)
c write(3,*)x(i)
seed=x(i)*m
x(i+1)=(seed*a)/m
150 continue
stop
End
Mixed Multiplicative Congruential Method:
Uniformity Test
Auto-Correlation test
Periodicity Test
Uniformity Test
Auto-Correlation test
Algorithm
Step1: initialize sum for average and sqaure
Step2: start loop over random numbers
Step3: sum the numbers
Step4:sum the square of numbers
Step5: loop started at step2 ends
Step6: find mean of squares
Step7: give interval b/w two random numbers for which correln is to be checked
Step8: Initialize the sum of products of no.s in pairs,nl and no. Of pairs choosen for correln
Step9: calculate the pairs of random no.s
Step10:start loop over nl
Step11: calculate sum of product of random numbers
Step12:calculate sum of random numbers
Step13: end of loop at step 10
Step14: Find average of products
Step15: calculate c(k)
Step16: program end
Periodicity Test
probabiltiy of hitting is
area⋅of⋅square 4 r 2 4
= =
area⋅of⋅circle πr 2 π
area⋅of⋅circle
π =4∗
area⋅of⋅square
data j,k,l/1000,53,1/
data j1,k1,l1/1000,53,1/
write(*,*)'no. of hits'
read(*,*)n
count=0
do 110 i=1,n
l=mod(k*l,j)
rn=float(l)/float(j)
l1=mod(k1*l1,j1)
rn1=float(l1)/float(j1)
write(*,*)rn,rn1
if((rn*rn+rn1*rn1).le. 1)count=count+1
write(*,*)count
110 continue
integ=count
pi=4*integ
write(*,*)pi
stop
end
Monte Carlo Integration for multi-dimensional integrals
Standard deviation
sum=sum+f(rn,rn1)
10 continue
sum=(b1-a1)*(b2-a2)*sum/n
write(*,*)sum
stop
end
write(3,*)i,t0,q0
7 i=i+1
s0=f(q0)
s1=f(q0+s0*h)
q1=q0+h*(s0+s1)/2.0
t0=t0+h
write(3,*)i,t0,q1
if(abs(qfinal-q1) .ge. 0.0001)then
q0=q1
qfinal=q1
go to 7
endif
stop
end
LCR circuits
0.5
charge
current
0
0 2 4 6 8 10 12 14 16
-0.5
-1
LCR-driven
1.5
0.5
0 charge
0 2 4 6 8 10 12 14 16 charge-driven
-0.5
-1
-1.5
-2
-2.5
pot(r)=(-1.0/r)+(l*(l+1)/(2.0*r*r))
read(*,*)l,rf,ro
read(*,*)e,h
i=0
r=0.05
zo=-1.902459
write(*,*)i,r,ro,rf
50 i=i+1
so=zo
po=-2.0*zo/r-2.0*(e-pot(r))*ro
p1=-2.0*(zo+po*h)/(r+h)-2.0*(e-pot(r+h))*(ro+so*h)
z1=zo+(po+p1)*h/2.0
s1=z1
r1=ro+(so+s1)*h/2.0
r=r+h
ra=2.0*exp(-r)
write(*,*)i,r,r1,ra
zo=z1
ro=r1
if(r.le.rf) goto 50
stop
end
R(r)
2
R(r)
1
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Interference pattern
Algorithm
Step1: Define
do 50 ipoint=0,npoint
y=ipoint+dy
call swave(y,ints)
write(3,*)y,ints
50 continue
continue
stop
end
subroutine swave(y,ints)
real k,ints
integer t
common a,d,k,nt
fun(r,tx)=amod((k*r-omg*tx),pi2)
pi=3.14159
pi2=2.0*pi
omg=2.0*pi/(2.0*nt)
ints=0
do 20 t=1,nt
tx=t
y1=y-0.5*a
y2=y-0.5*a
r1=d*d+y1*y1
r2=d*d+y2*y2
r1=sqrt(r1)
r2=sqrt(r2)
sum=sin(fun(r1,tx))/r1+sin(fun(r2,tx))/r2
ints=ints+sum*sum
20 continue
ints=ints/nt
return
end
Diffraction Pattern
2dsin=nλ
Algorithm
Step1: define
Step2: input parameters: λ, A, Ymax, D, Npts,no.of time steps N, size of grating
Step3: Find wave number,k and angular frequency ω
Step4: Find step size h=Ymax/Npts
Step5: begin loop to find intensity over screen points
Step6: find distance of the slits from points on the screen
Step7: initialize intensity I= 0
Step8: begin loop over time steps N
Step9:initialize sum of amplitudes, sum=0
Step10: begin loop over number of lines
Step11: find wave amplitude and add to sum
Step12: loop begun sat step 13 ends
Step13: intensity I= I + total Amplitude 2
Step14: end of loop begun at step 11
Step15: find average intensity = I/tN
Step16: loop begun at step 7 ends
Step17: program ends
Fortran Program
c program for diffraction
real k,ints
common ns,a,d,k,nt
open(3,file='diffr')
write(*,*)'enter the no. of slits'
read(*,*)ns
write(*,*)'enter the distance bw two slits'
read(*,*)a
write(*,*)'enter the distance D'
read(*,*)d
write(*,*)'enter the wavelength'
read(*,*)lam
write(*,*)'enter maximum position of ymax in mm'
read(*,*)ymax
write(*,*)'enter no of points on the screen npt'
read(*,*)npt
write(*,*)'enter the time period'
read(*,*)nt
alam=lam*1.0e-7
pi=3.14159
k=2*pi/alam
dy=ymax/npt
write(3,*)'position intensity'
do 50 ipt=-npt,npt
y=ipt+dy
call swave(y,ints)
write(3,*)y,ints
50 continue
stop
end
subroutine swave(y,ints)
real k,ints
integer t
common ns,a,d,k,nt
fun(r,tx)=amod((k*r-omg*tx),pi2)
pi=3.14159
pi2=2.0*pi
del=a/(ns-1)
omg=2*pi/(20.0*nt)
ints=0
do 20 t=1,nt
tx=t
sum=0.0
do 30 is=1,ns
y1=-0.5*a+(is-1)*del
r1=d*d+(y-y1)*(y-y1)
r=sqrt(r1)
sum=sum+cos(fun(r,tx))/r
30 continue
ints=ints+sum*sum
20 continue
ints=ints/nt
return
end
Oscillatory Motion
Program for simple harmonic oscillator
x(t)
2.00E+00
1.50E+00
1.00E+00
5.00E-01 x(t)
0.00E+00
0.00E+00
-5.00E-01 2.00E+00 4.00E+00 6.00E+00
-1.00E+00
-1.50E+00
-2.00E+00
Damped
1.2
1
0.8
0.6
0.4 x(t)
0.2 v(t)
0
-0.2 0 2 4 6 8 10 12 14 16
-0.4
-0.6
c driven harmonic oscillator
dimension t(2000),A(2000),v(2000),s(2000)
func(x,Y,Z)=(-k*x-c*Y+f0*cos(omega*Z)/m)
read(*,*)k,M,c
read(*,*)x0,v0,tmax,h
read(*,*)f0,omega
n=tmax/h
t(1)=0
s(1)=x0
v(1)=v0
a(1)=func(s(1),v(1),t(1))
do 230 i=1,n
t(i)=t(1)+h*i
write(3,*)t(i),v(i),s(i),a(i)
s(i+1)=s(i)+v(i)*h
a(i+1)=func(s(i+1),v(i),t(i+1))
v(i+1)=v(i)+a(i+1)*h
230 continue
stop
end
Simple pendulum
program for simple pendulum
c program for simple pendulum
write(*,*)'h,tf'
read(*,*)h,tf
g=9.8
l=1
tho=0.25
to=0.0
zo=0.0
i=0
write(*,*)to,tho,zo
50 i=i+1
so=zo
po=-g*sin(tho)/l
p1=-g*sin(tho+so+h)/l
z1=zo+h*(po+p1)/2.0
s1=z1
th1=tho+h*(so+s1)/2.0
to=to+h
write(*,*)to,th1,z1
zo=z1
tho=th1
if(to .lt. tf) goto 50
stop
end
c program for chaotic pendulum
f(x,v,t)=-1.0*c*v-(1+a*cos(w*t))*sin(x)
open(3,file='chpend')
write(*,*)'tmax,h'
read(*,*)tmax,h
write(*,*)'xo vo'
read(*,*)xo,vo
write(*,*)'c a w'
read(*,*)c,a,w
i=0
x=xo
v=vo
50 i=i+H
so=vo
k1=f(x,v,t)
k2=f(x+h*so/2,v+k1/2,t+h/2)
s1=vo+k1*h/2
k3=f(x+s1*h/2,v+k2*h/2,t+h/2)
s2=vo+k2*h/2
k4=h*f(x+s2*h,v+k3*h,t+h)
v=v+((h/6)*(k1+2.0*k2+2.0*k3+k4))
s3=v
x=x+((h/6)*(s1+2.0*s2+2.0*s3+s4))
write(*,*)t,x,v
t=t+h
if(t .lt. tmax) goto 50
10 continue
stop
end
Phase trajectories of chaotic pendulum
F(x,v,t)=-cv-(1+f cos(wt))*sin(x)
(i) c= 0 f=0
(ii) c= 1 f=0
(ii) c= 1 f=1
(iii) c= 1 f=3
(iv) c= 1 f=1.7
c growth of current in RL circuit
f(ci)=v/al-(r/al)*ci
v=4.0
r=2.0
al=1.0
h=0.1
ci0=0.0
t0=0.0
cifinal=ci0
i1=0
write(*,*)'n time current'
write(*,*)i1,t0,ci0
7 i1=i1+1
s0=f(ci0)
s1=f(ci0+s0*h)
ci1=ci0+h*(s0+s1)/2.0
t0=t0+h
write(*,*)i1,t0,ci1
if(abs(cifinal-ci1) .ge. 0.001) then
ci0=ci1
cifinal=ci1
goto 7
endif
stop
end
current
2.5
1.5 current
0.5
0
0 0.5 1 1.5 2 2.5 3 3.5
c
1.2
0.8
current
0.6
current-ana
0.4 v
0.2
0
0 0.5 1 1.5 2 2.5 3 3.5
Chaos
Chaos: Measurements on the system at given time might not allow the future to be
predicted with certainty, even if the force laws are known exactly! (Experimental
uncertainties in the initial conditions). Deterministic Chaos: Always associated with a system
nonlinearity. Nonlinearity: Necessary for chaos, but not sufficient! All chaotic systems are
nonlinear but not all nonlinear systems are chaotic.
Chaos occurs when the system depends very sensitively on its previous state. Even a
tiny change in initial conditions can completely change the system motion.
Chaotic Systems: Can only be solved numerically. Only with the availability of modern
computers has it become possible to study these phenomena. No simple, general rules for
when the system will be chaotic or not. Chaotic phenomena in the real world: Irregular
heartbeats, Planet motion in the solar system, Electrical circuits, Weather patterns, …
Chaos- complete disorder/confusion/disorder
Non-linearity in real physical processes
Chaotic system appear stochastic but are deterministic and still unpredictable
Chaotic systems are predictable at times and random at instants
Is interinsic property
Extremely sensitive to initial conditions (butterfly effect)
Chaotic behavior can only be found in systems of equations with three or more variables.
Attractors: set of points in phase space towards which system evolves
=4.9999
Scaling number: : ratio of sets of scales of trajectories splitting in two successive cycles at
bifurcation
= 2.50
Lyaponov exponents
=2.8
=3.45
=3.6