1. Apr 18, 2012

### mohammedalwar

Friends,
I have written a program in FOTRAN for solving a equation [f(t0,y0)= 1/2*(t-y) by EulerMethod

I'm in the learning stage of FOTRAN.
after executing my program and save the result in txt file
the result For example be
1.000000000000000 1.000000000000000
2.000000000000000 1.000000000000000
3.000000000000000 1.000000000000000
4.000000000000000 1.000000000000000
5.000000000000000 1.000000000000000
6.000000000000000 1.000000000000000
7.000000000000000 1.000000000000000
8.000000000000000 1.000000000000000
9.000000000000000 1.000000000000000
I don't know what the problem in this function; because the other function working perfectly
as f(t0,y0)= (t+y)

So please don't mind if my program has got any silly mistakes.

My code

program EulerMethod
implicit none
real(8)::a,b,h,y_0,t

print*,"Enter the interval a,b ,the value of the step-size h and the value of y_0"

open(1, file="resultEuler.txt",status='new',position="rewind")

call euler(y_0,a,b,h)
close(1)

contains
subroutine euler(y_0,a,b,h)
implicit none
real(8), intent(inout)::a,h,b,y_0
real(8):: y,t
t=a
y=y_0
do while(t<=b)
y=y+h*f(y,t)
write(1,*)t, y
t=t+h
end do
end subroutine
function f(y,t)
implicit none
real(8)::f,y,t

f=1/2*(t-y)

end function

end program EulerMethod

2. Apr 18, 2012

### Bill Simpson

Please provide the input a,b,h,y_0 for a simple example and what the output should be.

Just saying "it prints 1,2,3,4,5,6,7,8. what is wrong with it?" doesn't give enough information for someone to be able to step through the problem and find the error.

3. Apr 18, 2012

### Staff: Mentor

I suspect that your f function is causing problems.
Code (Text):

function f(y,t)
implicit none
real(8)::f,y,t

f=1/2*(t-y)
end function

In the value you return, you should replace 1/2 by 0.5. I'm pretty sure that 1/2 is causing your function to always return 0. This is because 1/2 evaluates to 0. In other words, integer division is being performed, not floating point division.

BTW, the name of the language is FORTRAN.

4. Apr 18, 2012

### mohammedalwar

^_______^ Thanks guys
thank you Mark44 for found the problem ,,, my program running perfectly .....

BTW, I know the name of this language is ForTran ,,,, but i had syntax error hhhhhhhh
.... Thank you again
Bye :)

5. Apr 18, 2012

### Staff: Mentor

Good to hear.