Need in solving a programm in FOTRAN

  • Thread starter Thread starter Sampath Emani
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around a FORTRAN program intended to solve a differential equation using the Runge-Kutta method. Participants are addressing issues related to the program's structure, variable usage, and potential errors in the code.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant shares a FORTRAN program for solving the equation f(x0,y0) = 2*(y**2) + 5 and requests assistance in executing it.
  • Another participant questions the purpose of the subroutine 'runge' as it appears unused in the program.
  • Concerns are raised about the function 'rk' being declared with one argument while being called with three arguments.
  • A participant acknowledges the issues pointed out and seeks help in correcting the program, specifically for implementing the Runge-Kutta method.
  • Further critiques highlight the need for "IMPLICIT NONE" in the program and subroutines, the undefined variable "f," and inconsistencies in variable names for input values.

Areas of Agreement / Disagreement

Participants generally agree that there are multiple issues with the program that need addressing, but no consensus is reached on the specific corrections or the best approach to rectify the code.

Contextual Notes

Limitations include missing definitions for certain variables, potential misunderstandings regarding the function calls, and the need for clearer variable management in the program.

Sampath Emani
Messages
2
Reaction score
0
Friends,
i have written a program in FOTRAN for solving a equation [f(x0,y0)= 2*(y**2)+5]
I'm in the learning stage of FOTRAN. So please don't mind if my program has got any silly mistakes.
Please help in executing the program.

program rungekutta


print *,' DIFFERENTIAL EQUATION WITH 1 VARIABLE OF ORDER 1'

print*,"enter the value of x0"
read*,x

print*,"enter the value of y0"
read*,y

print*,"enter the value of step size"
read*,h

print*,"solution for the equation is",rk(x0,y0,h)


call runge(m,f1,n,h,x1)

end

function rk(y) result(r)

!Example: y'=(2*y^2+5)

real y,r

r = (2*(y**2)+5)
end function rk(y)

Subroutine runge(m,f1,n,h,x1)

integer f1,i,j,m,n,h

real x,w1,w2,w3,w4,x0,y;

do i=1, m
ni = (i - 1) * f1 - 1
do j=1, f1
x = x1 + h * (n + j)
w1 = h * f(x0,y0)
w2 = h * f(x0+h/2, y0+w1/2)
w3 = h * f(x0+h/2, y0+w2/2)
w4 = h * f(x0+h, y0+w3)
x = x0 + h

x = y + (w1 + w2 + w2 + w3 + w3 + w4) / 6

end do

end do

end
 
Technology news on Phys.org
what does the subroutine runge do for you? it is not being used anywhere.

why if function rk is declared with 1 argument, you pass 3 to it?
 
yes sir,
i do agree. but I'm not able not correct that .
Can u help me in writing the correct step.
I took an equation (2*(y**2)+5)
i want to solve this using Runge kutta.
Thanks in advance
 
Sampath Emani said:
Friends,
i have written a program in FOTRAN for solving a equation [f(x0,y0)= 2*(y**2)+5]
I'm in the learning stage of FOTRAN. So please don't mind if my program has got any silly mistakes.
Please help in executing the program.

program rungekutta


print *,' DIFFERENTIAL EQUATION WITH 1 VARIABLE OF ORDER 1'

print*,"enter the value of x0"
read*,x

print*,"enter the value of y0"
read*,y

print*,"enter the value of step size"
read*,h

print*,"solution for the equation is",rk(x0,y0,h)


call runge(m,f1,n,h,x1)

end

function rk(y) result(r)

!Example: y'=(2*y^2+5)

real y,r

r = (2*(y**2)+5)
end function rk(y)

Subroutine runge(m,f1,n,h,x1)

integer f1,i,j,m,n,h

real x,w1,w2,w3,w4,x0,y;

do i=1, m
ni = (i - 1) * f1 - 1
do j=1, f1
x = x1 + h * (n + j)
w1 = h * f(x0,y0)
w2 = h * f(x0+h/2, y0+w1/2)
w3 = h * f(x0+h/2, y0+w2/2)
w4 = h * f(x0+h, y0+w3)
x = x0 + h

x = y + (w1 + w2 + w2 + w3 + w3 + w4) / 6

end do

end do

end

There are at least several problems that you need to rectify.
(In future, include all the error messages with your post, along with the
source.)

1. You need "IMPLICIT NONE" in the program and in each subroutine
and function.

2. What is "f"?

3. when you invoke rk, it is with 3 arguments.
Yet the function is defined with only one dummy argument.

4. You requested the input of "x0", but you read the value into "x", etc.
 

Similar threads

  • · Replies 36 ·
2
Replies
36
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 89 ·
3
Replies
89
Views
6K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K