Welcome to our community

Be a part of something great, join today!

Fortran programming to solve ode


Dec 26, 2012
Consider the first order differential equation
\[\frac{dy}{dy} = f(t,y) = -16 t^3 y^2\]
with initial condition $y(0)=1$

Using second order Adams-Bashforth method, write a Fortran programming to generate an approximate solution to the problem.
Program adams
Implicit None
Real, allocatable :: $y:)),t:))$
Real:: yo, tend, h, k1,k2
Integer:: NI, i
Real,external ::f

!Asking to enter the initial vaule of yo, final time and numbers of step
Print*, 'Enter yo,Tend,NI'
read*, yo,Tend,NI
h= Tend/NI
Print*, 'This gives stepsize h=',h
allocate (t(0:NI), y(0:NI))

!Initial Conditions
y(0) = 1

!After using runge kutta method, found out k1 =0 and k2= -16h^3,
k2= -16*h**3

!we know that y(n+1) =y(n) + h/2(k1+K2) at n=0
y(1) = y(0) + h/2 *( k1+ k2)

! Loop through the number of steps to calculate the following at each step
do i=2, NI
t(i)= i*h
write(10,*) i, t(i),t(i-1)
!Second order Adam bashforth for all n
y(i)= y(i-1) + (h/2)*(3*f(t(i-1), y(i - 1))- f(t(i-2), y(i-2)))
end do
end program adams

!declaring function
Real Function f(t,y)
Real:: t
Real:: y
f = - 16*t**3*y**2
End Function f

Now i want to plot this partial derivative ∂f/∂y = |-32 (4t^4 +1)^-1 t^3| against t using fortran to generate a file or something for the matlab to plot the graph.
Can someone help me
Last edited by a moderator: