Scope of variables in Fortran

Categories: Code
Fortran has an option of local variables called SAVE. If this option is added, its value will be kept until the end of program. To clarify, let's say if the code is like the following: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 program main integer :: a = 1 write(*,*) "a=",a call add1(a) write(*,*) "a=",a call add1(a) write(*,*) "a=",a end program subroutine add1(a) integer,save :: b integer :: a write(*,*) "b=",b b=1 a = a+b b = b+1 end subroutine No matter how do you compile it, the output will be like the following:

Read More →

Solve a Nonlinear Second Order ODE

Categories: Math
The problem is how to solve the following ODE: $$ \ddot{x} = A\exp\left(-Bx\right)$$ with the following initial condition: $$ x(0)=0,\quad x'(0)=0$$ The actual method is quite traditional. We first make $v(t)=\dot{x}(t)$, then the ODE becomes: $$v\frac{dv}{dx}=A\exp(-Bx)$$ The general solution of it is: $$\frac{v^2}{2}=-\frac{A}{B}\exp(-Bx)+C$$ Using the initial condition: $$\dot{x}=\sqrt{\frac{2A}{B}\left[1-\exp(-Bx)\right]}$$ The tricky part now is we make a another substitution now and make $y=\exp(-Bx)$, then we get: $$-\frac{\dot{y}}{By}=\sqrt{\frac{2A}{B}\left[1-y\right]}$$ Then the following ODE can be easily solved: $$\dfrac{dy}{y\sqrt{1-y}}=-\sqrt{2AB}dt$$ The result: $$\log\left(\dfrac{1-\sqrt{1-y}}{1+\sqrt{1-y}}\right)=-\sqrt{2AB}t$$

Read More →

Units Converter

Energy Units Converter Enter your energy value in the box with the appropriate units, then press "tab" or click outside of the input box. Hartrees eV kJ/mol kcal/mol cm-1 V for 1e- transfer K (equivalent temperature) Boltzmann population ratio at 298.15K Joule cal/mol Angstrom Energy Units Converter Enter your energy value in the box with the appropriate units, then press "tab" or click outside of the input box.

Read More →