Please help me: a problem on my FOTRAN program

  • Thread starter Thread starter mohammedalwar
  • Start date Start date
  • Tags Tags
    Program
Click For Summary

Discussion Overview

The discussion revolves around a FORTRAN program intended to solve a differential equation using the Euler method. Participants explore issues related to the program's output and identify potential errors in the code.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • The original poster shares their FORTRAN code and output, expressing confusion about why the function returns constant values.
  • One participant requests specific input values and expected output to better understand the issue.
  • Another participant suggests that the problem may lie in the function definition, specifically pointing out that using "1/2" may lead to integer division, which could cause the function to always return zero.
  • The original poster acknowledges the feedback and indicates that correcting the division resolved the issue, leading to successful program execution.
  • There is a light-hearted exchange regarding the correct spelling of "FORTRAN," with the original poster admitting to a syntax error.

Areas of Agreement / Disagreement

Participants generally agree on the identification of the problem with the function definition, but the discussion does not delve into further technical details or alternative solutions.

Contextual Notes

Limitations include the original poster's initial lack of clarity in describing the problem and the reliance on specific input values for troubleshooting.

Who May Find This Useful

Individuals learning FORTRAN, those interested in numerical methods like the Euler method, and programmers seeking help with debugging similar issues may find this discussion beneficial.

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
2K
  • · 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