Differential equation in fortran

In summary, in order to do numerical computation using the fourth order Runge Kutta algorithm in Fortran, the conversation suggests defining complex functions for the set of differential equations and using complex variables for x and y. However, the incorrect definition of f and g causes errors. An alternative approach is to convert the equations into a set of equations in 4 real variables, the real and imaginary parts of x and y.
  • #1
nirajaryal
1
0
I need to do numerical computation by fourth order Runge Kutta Algorithm
in fortran. But I stuck in programming because the differential
equation contains imaginary part.

Take for e.g. the set of diff.equation are
x'=(i)y *exp(iwt) ;where i is imaginary no. and w is constant!
y'=(i)x*exp(iwt)

I tried to define complex function f and g as
f=(0,y *exp(iwt))
g=(0,x *exp(iwt))

and i defined x and y as real (because the argument of the complex
no.has to be real,right?/otherwise it doesn't accept)
But after every iteration,the x and y becomes real as
x=x0+some linear combination of the function f(which is complex)//and
real +complex gives complex no. and hence shows error!
So i unable to proceed further! So how should I proceed?
 
Technology news on Phys.org
  • #2
nirajaryal said:
Take for e.g. the set of diff.equation are
x'=(i)y *exp(iwt) ;where i is imaginary no. and w is constant!
y'=(i)x*exp(iwt)

I tried to define complex function f and g as
f=(0,y *exp(iwt))
g=(0,x *exp(iwt))

and i defined x and y as real (because the argument of the complex
no.has to be real,right?

That is wrong, because your definitions of f and g are not the same as your differential equation.

Try something like this:
define ZI as a complex constant = (0.0, 1.0)
Make X, Y, F and G all complex
and then do
F = ZI * X * exp(ZI * W * T)

Alternatively, you could convert this to a set of equations in 4 real variables, the real and imaginary parts of x and y. Since exp(iwt) = cos wt + i sin wt

If you write x = xr + i xi and y = yr + i yi, where xr, xi, yr, yi are real, then

i * y *exp(iwt) = (i yr - yi) (cos wt + i sin wt)
= -yi cos wt + yr sin wt + i (yr cos wt - yi sin wt)

So you would have

xr' = -yi cos wt + yr sin wt
xi' = yr cos wt - yi sin wt
and similar equations for yr' and yi'
 

Related to Differential equation in fortran

1. What is a differential equation?

A differential equation is a mathematical equation that describes the relationship between a function and its derivatives. It is used to model and solve problems in various fields such as physics, engineering, and economics.

2. Why is Fortran commonly used for solving differential equations?

Fortran is commonly used for solving differential equations because it is a high-level programming language that is designed for scientific and numerical computations. It has built-in libraries and functions that make it efficient and accurate for solving complex mathematical problems.

3. How do you write a differential equation in Fortran?

To write a differential equation in Fortran, you first need to define the variables and parameters of the equation. Then, use the built-in functions and operators to represent the mathematical operations and relationships in the equation. Finally, use a loop to solve the equation iteratively.

4. Can Fortran solve any type of differential equation?

Fortran can solve a wide range of differential equations, including ordinary differential equations (ODEs), partial differential equations (PDEs), and systems of differential equations. However, the complexity and accuracy of the solution may vary depending on the equation and the method used.

5. How do I verify the accuracy of the solution obtained from Fortran code?

To verify the accuracy of the solution obtained from Fortran code, you can compare it with the exact analytical solution, if available. You can also vary the parameters and boundary conditions of the equation and observe the changes in the solution. Additionally, you can use convergence tests to check the stability and accuracy of the solution.

Similar threads

  • Programming and Computer Science
Replies
4
Views
957
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
949
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
9K
Replies
4
Views
3K
  • Programming and Computer Science
Replies
2
Views
827
  • Programming and Computer Science
Replies
8
Views
3K
Replies
0
Views
520
Back
Top