- #1

- 56

- 0

Adapt the fortran programming using second order adams bashforth method to generate a numerical solution of the Lorenz system:

dx/dt =-10x+10y

dy/dy=28x-y-x*z

dz/dt= x*y- (8/3)*z

with initial condition x(0)=y(0)=0, z(0)=2 slightly perturbed. Plot x and z against t runs from 0 to 15, and also z against x for a chosen value of h.

Here is my programming:

Program adamsthree

Implicit None

Real, allocatable :: y(:),t(:),z(:),x(:)

Real:: tend, h, k1,k2,k3,k4,k5,k6

Integer:: NI, i

Real,external ::f

Print*, 'Enter the final time '

read*, Tend

Print*, 'Enter number of timesteps to take'

read*, NI

h= Tend/NI

Print*, 'This gives stepsize h=',h

allocate (t(0:NI), y(0:NI),x(0:NI),z(0:NI))

!Initial Conditions

t(0) = 0

x(0) = 0

y(0) = 0

z(0) = 2

!After using runge kutta method I found out:

!k1 =0 and k2= 27h, k3=-16/3,k4=h-(32/3),k5=0,k6 =-10*h+h

k1 = 0

k2= 27*h

k3=-16/3

k4= h-(32/3)

k5 = 0

k6 = -10*h+h

!we know that y(i+1) =y(i) + h/2(k1+k2),z(i+1) = z(n) + h/2(k3+k4)

! x(i+1) =x(i) + h/2(k5+k6) at i=0

y(1) = y(0) + h/2 *( k1 + k2)

z(1)= z(0) + h/2 *( k3 + k4)

x(1)= x(0) + h/2 *( k5 + k6)

t(1) = h

open(10,file='adams_threeresults.m')

! Loop through the number of steps to calculate the following at each step

do i = 2, NI

t(i) = i*h

!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)))

x(i) = x(i-1) + (h/2)*(3*f(t(i-1), x(i - 1))- f(t(i-2), x(i-2)))

z(i) = y(i-1) + (h/2)*(3*f(t(i-1), z(i - 1))- f(t(i-2), z(i-2)))

end do

!Print out the Approximate solution

write(10,*) 'x =[', t(0),x(0)

do i = 0, NI

write(10,*) t(i),x(i)

end do

write(10,*) t(NI),x(NI),']'

write(10,*) 'y =[', t(0),y(0)

do i = 0, NI

write(10,*) t(i),y(i)

end do

write(10,*) t(NI),y(NI),']'

write(10,*) 'z =[', t(0),z(0)

do i = 0, NI

write(10,*) t(i),z(i)

end do

write(10,*) t(NI),x(NI),']'

write(10,*) "plot(time,'or',x(:,1),x(:,2),'g',z:,1),z(:,2),'r')"

write(10,*) "xlabel('time'),ylabel('y'),legend('x and z','time')"

write(10,*) "plot(x(:,1),x(:,2),'g',z:,1),z(:,2),'r')"

write(10,*) "xlabel('time'),ylabel('y'),legend('x against z')"

close(10)

end program adamsthree

!declaring function

Real Function f(t,y)

Real:: t

Real:: y

f = 28*x-y-x*z

End Function f

Real Function f(t,x)

Real:: t

Real:: x

f = -10*x + 10*y

End Function f

Real Function f(t,z)

Real:: t

Real:: z

f = x*y - (8/3)*z

End Function f

(I am trying to creat a file for mathlab to plot the graph.)

I got these warning:

warning 767 - The argument T has not been used

warning 298 - Variable X has been used without being given an initial value

warning 298 - Variable Z has been used without being given an initial value

warning 767 - The argument T has not been used

warning 298 - Variable Y has been used without being given an initial value

warning 767 - The argument T has not been used

warning 298 - Variable X has been used without being given an initial value

warning 298 - Variable Y has been used without being given an initial value

*** Multiple definition of symbol: _F

\\ndrive\tg813934\.do_not_delete\desktop.xp\Project 1\lgotemp@.obj

(\\NDRIVE\TG813934\.DO_NOT_DELETE\DESKTOP.XP\PROJECT 1\ADAMSTHREE.F95)

and,

\\ndrive\tg813934\.do_not_delete\desktop.xp\Project 1\lgotemp@.obj

(\\NDRIVE\TG813934\.DO_NOT_DELETE\DESKTOP.XP\PROJECT 1\ADAMSTHREE.F95)

*** Compilation abandoned

Compilation failed.

dx/dt =-10x+10y

dy/dy=28x-y-x*z

dz/dt= x*y- (8/3)*z

with initial condition x(0)=y(0)=0, z(0)=2 slightly perturbed. Plot x and z against t runs from 0 to 15, and also z against x for a chosen value of h.

Here is my programming:

Program adamsthree

Implicit None

Real, allocatable :: y(:),t(:),z(:),x(:)

Real:: tend, h, k1,k2,k3,k4,k5,k6

Integer:: NI, i

Real,external ::f

Print*, 'Enter the final time '

read*, Tend

Print*, 'Enter number of timesteps to take'

read*, NI

h= Tend/NI

Print*, 'This gives stepsize h=',h

allocate (t(0:NI), y(0:NI),x(0:NI),z(0:NI))

!Initial Conditions

t(0) = 0

x(0) = 0

y(0) = 0

z(0) = 2

!After using runge kutta method I found out:

!k1 =0 and k2= 27h, k3=-16/3,k4=h-(32/3),k5=0,k6 =-10*h+h

k1 = 0

k2= 27*h

k3=-16/3

k4= h-(32/3)

k5 = 0

k6 = -10*h+h

!we know that y(i+1) =y(i) + h/2(k1+k2),z(i+1) = z(n) + h/2(k3+k4)

! x(i+1) =x(i) + h/2(k5+k6) at i=0

y(1) = y(0) + h/2 *( k1 + k2)

z(1)= z(0) + h/2 *( k3 + k4)

x(1)= x(0) + h/2 *( k5 + k6)

t(1) = h

open(10,file='adams_threeresults.m')

! Loop through the number of steps to calculate the following at each step

do i = 2, NI

t(i) = i*h

!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)))

x(i) = x(i-1) + (h/2)*(3*f(t(i-1), x(i - 1))- f(t(i-2), x(i-2)))

z(i) = y(i-1) + (h/2)*(3*f(t(i-1), z(i - 1))- f(t(i-2), z(i-2)))

end do

!Print out the Approximate solution

write(10,*) 'x =[', t(0),x(0)

do i = 0, NI

write(10,*) t(i),x(i)

end do

write(10,*) t(NI),x(NI),']'

write(10,*) 'y =[', t(0),y(0)

do i = 0, NI

write(10,*) t(i),y(i)

end do

write(10,*) t(NI),y(NI),']'

write(10,*) 'z =[', t(0),z(0)

do i = 0, NI

write(10,*) t(i),z(i)

end do

write(10,*) t(NI),x(NI),']'

write(10,*) "plot(time,'or',x(:,1),x(:,2),'g',z:,1),z(:,2),'r')"

write(10,*) "xlabel('time'),ylabel('y'),legend('x and z','time')"

write(10,*) "plot(x(:,1),x(:,2),'g',z:,1),z(:,2),'r')"

write(10,*) "xlabel('time'),ylabel('y'),legend('x against z')"

close(10)

end program adamsthree

!declaring function

Real Function f(t,y)

Real:: t

Real:: y

f = 28*x-y-x*z

End Function f

Real Function f(t,x)

Real:: t

Real:: x

f = -10*x + 10*y

End Function f

Real Function f(t,z)

Real:: t

Real:: z

f = x*y - (8/3)*z

End Function f

(I am trying to creat a file for mathlab to plot the graph.)

I got these warning:

warning 767 - The argument T has not been used

warning 298 - Variable X has been used without being given an initial value

warning 298 - Variable Z has been used without being given an initial value

warning 767 - The argument T has not been used

warning 298 - Variable Y has been used without being given an initial value

warning 767 - The argument T has not been used

warning 298 - Variable X has been used without being given an initial value

warning 298 - Variable Y has been used without being given an initial value

*** Multiple definition of symbol: _F

\\ndrive\tg813934\.do_not_delete\desktop.xp\Project 1\lgotemp@.obj

(\\NDRIVE\TG813934\.DO_NOT_DELETE\DESKTOP.XP\PROJECT 1\ADAMSTHREE.F95)

and,

\\ndrive\tg813934\.do_not_delete\desktop.xp\Project 1\lgotemp@.obj

(\\NDRIVE\TG813934\.DO_NOT_DELETE\DESKTOP.XP\PROJECT 1\ADAMSTHREE.F95)

*** Compilation abandoned

Compilation failed.

Last edited: