Spring pendulum system fortran program

In summary, the author is trying to solve a Pendulum-Spring system with equations of motion. They made a mistake with the name of the code, and are using Euler's Method instead of Runge-Kutta. They need help with converting the equations of motion into four 1st-order ODEs, and then solving them.
  • #1
Casco
82
1
I just want to know if someone has the fortran code for the numerical solution of the pendulum with a spring. And if it is so, can it write it here?
 
Physics news on Phys.org
  • #2
Casco said:
I just want to know if someone has the fortran code for the numerical solution of the pendulum with a spring. And if it is so, can it write it here?

Have you tried to do this on your own already? https://www.physicsforums.com/showthread.php?t=94379" Show what you've done so far so we can help you.
 
Last edited by a moderator:
  • #3
Ok, this is what I have:

PROGRAM DIFFERENTIAL_EQUATIONS_SYSTEM

WRITE (*,*) 'WRITE A, B, N, ALF1 AND ALF2'
READ (*,*) A,B,N,ALF1,ALF2
H=(B-A)/N
T=A
W1=ALF1
W2=ALF2

OPEN(10,FILE='RUNGE_KUTTA_HIGHER_ORDER.TXT')

DO I=1,N

WRITE (10,*) T,W2
WRITE (*,*) T,W2

W1=W1+H*F1(T,W1,W2)
W2=W2+H*F2(T,W1,W2)
T=A+I*H

END DO
END

FUNCTION F1(T,W1,W2)
REAL W1,W2,T
F1=W1
RETURN
END

FUNCTION F2(T,W1,W2)
REAL W1,W2,T
F2=-3.0*W2-(9.8/3.0)*SIN(W1)
RETURN
END

maybe my way of programming is not the best. What I have are the equations of motion for the pendulum-spring system, they are coupled, and I don't know how to solve them numerically, any help?

And it would be any advice to improve my programming it is welcomed.
 
  • #4
Could you please explain a bit more about the problem and your code? When you say pendulum-spring system, do you mean a rigid pendulum with a mass on the end is hanging from a spring? Can you show us the equations of motion you're using? And what method are you trying to use, 2nd-order Runge-Kutta?

As for the variables, I'm guessing A and B are initial and final times, N is number of timesteps, ALF1 and ALF2 are initial angles of the spring and pendulum, respectively. Correct? More descriptive variable names in general are very helpful if anyone besides yourself needs to understand your code.

A Fortran tip you may not be aware of: declare your variables explicity everywhere (like how you did in your functions: REAL W1,W2,T), and put IMPLICIT NONE as the first line in all of your programs and functions/subroutines, which forces you to declare your varibles. If you do not explicity declare varibles, Fortran implicity does so in the following manner. If the first letter of your variable name is I, J, K, L, M or N, it will be an INTEGER, otherwise it will be a REAL. This is widely considered to be one of the worst features of Fortran, and using IMPLICIT NONE is always recommended. In your code there are no problems with this, but it's easy to make mistakes.
 
  • #5
PICsmith said:
Could you please explain a bit more about the problem and your code? When you say pendulum-spring system, do you mean a rigid pendulum with a mass on the end is hanging from a spring? Can you show us the equations of motion you're using? And what method are you trying to use, 2nd-order Runge-Kutta?

The theory is on the pages 42-43 of the book.pdf file. I made a mistake with the name of the code, the method it isn't Runge-Kutta it is Euler's Method but for a second order differential equation.

All you assume on second paragraph it is right, about the variables. And thanks for the tip, I will keep it in mind.
 

Attachments

  • book.pdf
    205.1 KB · Views: 505
Last edited:
  • #6
You'll have to introduce some phase/state variables to convert those two 2nd-order ODEs into four 1st-order ODEs, and then solve those. http://12000.org/my_courses/UC_davis/spring_2011/MAE_121_eng_dynamics/lab/lab_one/report/report.htm" (eqn 3 and the ones above it). Hope that helps.
 
Last edited by a moderator:

Related to Spring pendulum system fortran program

1. What is a spring pendulum system?

A spring pendulum system is a physical system that consists of a mass attached to a spring, which is in turn attached to a fixed point. When the mass is displaced from its equilibrium position, the spring exerts a restoring force that causes it to oscillate back and forth.

2. Why is a Fortran program used for simulating a spring pendulum system?

Fortran is a high-level programming language that is commonly used in scientific and engineering fields. It is well-suited for mathematical computations and allows for efficient and accurate simulations of physical systems, such as the spring pendulum system.

3. How does the Fortran program simulate the spring pendulum system?

The Fortran program uses numerical integration methods, such as the Euler or Runge-Kutta methods, to solve the differential equations that describe the motion of the spring pendulum system. These methods use small time steps to approximate the position and velocity of the mass at each time interval, resulting in an accurate simulation of the system's behavior.

4. Can the Fortran program be used to study different parameters of the spring pendulum system?

Yes, the Fortran program can be easily modified to study different parameters of the system, such as the mass, spring constant, and initial conditions. This allows for a comprehensive analysis of how these parameters affect the motion of the spring pendulum system.

5. Is the Fortran program user-friendly?

The level of user-friendliness may vary depending on the specific program, but in general, Fortran programs can be considered user-friendly for those with a background in programming and scientific knowledge. The code is usually well-documented and can be easily modified to suit the user's needs.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
2
Replies
62
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
3K
  • Programming and Computer Science
Replies
25
Views
494
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
5K
Back
Top