Please help me: a problem on my FOTRAN program

  • Thread starter mohammedalwar
  • Start date
  • Tags
    Program
In summary, the conversation is about a program written in FORTRAN for solving an equation using the Euler Method. The program is being tested and the user is asking for help in identifying any mistakes. After some discussion, it is discovered that the function causing the issue was using integer division instead of floating point division. Once this issue is fixed, the program runs perfectly.
  • #1
mohammedalwar
2
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
  • #2
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
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 FORTRAN.
 
  • #4
^_______^ 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
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 :)
 

FAQ: Please help me: a problem on my FOTRAN program

1. Why is my FOTRAN program not running?

There could be several reasons why your FOTRAN program is not running. Some common issues include syntax errors, missing libraries, or incorrect input parameters. It is important to carefully check your code for any errors and ensure that all necessary libraries are included.

2. How do I debug my FOTRAN program?

To debug your FOTRAN program, you can use a debugger tool such as gdb or a debugging feature provided by your FOTRAN compiler. This will allow you to step through your code and identify any errors or issues that may be causing your program to malfunction.

3. What is the best way to optimize my FOTRAN program?

To optimize your FOTRAN program, you can use techniques such as loop unrolling, vectorization, and parallelization. It is also important to carefully choose data types and algorithms for efficient execution. Additionally, regularly profiling your program can help identify any areas that may need optimization.

4. How can I improve the performance of my FOTRAN program?

To improve the performance of your FOTRAN program, you can try using compiler flags or optimization options. You can also consider using a more efficient algorithm or data structure, as well as parallelizing your code for faster execution. Regularly profiling and benchmarking your program can also help identify areas for improvement.

5. Where can I find resources for learning FOTRAN?

There are many online resources available for learning FOTRAN, including tutorials, documentation, and forums. Some popular websites for FOTRAN learning include Fortran Wiki, Fortran Discourse, and Fortran Forum. You can also find books and online courses on FOTRAN programming for more in-depth learning.

Similar threads

Replies
15
Views
33K
Replies
4
Views
3K
Replies
4
Views
1K
Replies
8
Views
1K
Replies
20
Views
2K
Replies
4
Views
3K
Back
Top