Please help me: a problem on my FOTRAN program

  • Thread starter Thread starter mohammedalwar
  • Start date Start date
  • Tags Tags
    Program
mohammedalwar
Messages
2
Reaction score
0
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"
read*,a,b,h,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
 
Technology news on Phys.org
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.
 
I suspect that your f function is causing problems.
Code:
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 FOR[/color]TRAN.
 
^_______^ 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 :)
 
mohammedalwar said:
^_______^ Thanks guys
thank you Mark44 for found the problem ,,, my program running perfectly ...
Good to hear.
mohammedalwar said:
BTW, I know the name of this language is ForTran ,,,, but i had syntax error hhhhhhhh
... Thank you again
Bye :)
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 15 ·
Replies
15
Views
34K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K