Nugroho's blog.: The Answer of My Introduction Mathemathical for Physicist (Jawaban ujian Fismatku)

## Saturday, November 29, 2008

### The Answer of My Introduction Mathemathical for Physicist (Jawaban ujian Fismatku)

I use fortran to generate x n y position:

below is the code

PROGRAM Grafik
IMPLICIT NONE
REAL :: gaya,ygaya,k,ky,a,ay,m,v,vy,t,x,y,z
REAL :: sbx,sby,sbz,g,fx,fy,fz
REAL :: r,dt,dx,dy,dz,dv,dvy,theta,phi
INTEGER :: i,j,n
r =100
g =10
n =50
k =10000
ky =1000
t=0
dt=0.001
OPEN (80, FILE = 'data.dat', STATUS = 'NEW', FORM = 'FORMATTED')
WRITE(80,*) ' i t x y'
CLOSE(80)
OPEN(80, ACCESS = 'APPEND', FILE = 'data.dat', FORM = 'FORMATTED')
DO i=-n,n
x=i
x=x/10
IF (x .NE. 1) THEN
!y=(2+x-x*x)/(x-1)/(x-1)
z=2-x-x*x
vy=(x-1)*(x-1)
y=z/vy
END IF
WRITE(80,81) x,y
8¹FORMAT(e14.7,' ',e14.7)
END DO
CLOSE(80)
END PROGRAM Grafik

compile using:

\$gfortran grafik.f90

that syntax has output a.out
run using:

\$./a.out

It'll create file named data.dat and generate number of f(x)=(2-x-x^2)/(x-1)^2

plot using kst :
\$kst -x ¹-y 2 data.dat

It means kst will plot a graph using 1st column as x-axis and 2nd column as y-axis of data.dat

to simplify that procedure, I create text file named run.sh contain:

rm *.dat
gfortran grafik.f90
./a.out
kst -x ¹-y 2 data.dat

make run.sh executable
then run:
\$./run.sh

.........dan mereka hidup bahagia berdua selamanya.